player.java から player_name.java までの配列値を受け取りたいです。player_name.java のボタンをクリックすると NumberFormatException が発生します。
これら 2 つのアクティビティで 2 つのインテントを使用しました。配列を渡すインテントを 1 つ削除すると機能しますが、それ以外の場合は機能しません
単一のアクティビティで複数のインテントを使用するにはどうすればよいですか? 助けてください。
player.java
public class players extends Activity {
LinearLayout player_layout;
Bundle b;
List<EditText> allEds = new ArrayList<EditText>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.players);
b = getIntent().getExtras();
String resStr = b.getString("name");
player_layout = (LinearLayout) findViewById(R.id.player_layout);
EditText[] ed1 = new EditText[Integer.parseInt(resStr)+1];
Button add_player = new Button(players.this);
add_player.setText("Add Players");
for(int i=1; i <= Integer.parseInt(resStr); i++)
{
ed1[i] = new EditText(players.this);
allEds.add(ed1[i]);
player_layout.addView(ed1[i]);
ed1[i].setId(i);
ed1[i].setHint("enter player" +i+ "name");
ed1[i].setHeight(50);
ed1[i].setWidth(300);
}
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
player_layout.addView(add_player, lp);
add_player.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(players.this, player_name.class);
Intent intent1 = new Intent(players.this, player_name.class);
String[] strings = new String[allEds.size()];
for(int i=0; i < allEds.size(); i++){
strings[i] = allEds.get(i).getText().toString();
// intent.putExtra("playerName",b.getString("name"));
intent.putExtra("playerName",strings);
}
intent1.putExtra("play", b.getString("name"));
startActivity(intent);
startActivity(intent1);
}
});
}
}
player_name.java
public class player_name extends Activity {
LinearLayout player_name;
Bundle b,b1;
List<TextView> allEds = new ArrayList<TextView>();
List<Button> allplus = new ArrayList<Button>();
List<Button> allminus = new ArrayList<Button>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.player_name);
b = getIntent().getExtras();
String resStr = b.getString("name");
b1 = getIntent().getExtras();
String[] result = b1.getStringArray("playerName");
player_name = (LinearLayout) findViewById(R.id.player_name);
TextView[] ed1 = new TextView[Integer.parseInt(resStr)+1];
Button[] plus = new Button[Integer.parseInt(resStr)+1];
Button[] minus = new Button[Integer.parseInt(resStr)+1];
for(int i=1;i<=Integer.parseInt(resStr);i++)
{
ed1[i] = new TextView(player_name.this);
plus[i] = new Button(player_name.this);
minus[i] = new Button(player_name.this);
allEds.add(ed1[i]);
allplus.add(plus[i]);
allminus.add(minus[i]);
player_name.addView(ed1[i]);
player_name.addView(plus[i]);
player_name.addView(minus[i]);
ed1[i].setId(i);
ed1[i].setHeight(50);
ed1[i].setWidth(300);
ed1[i].setText(result[i]);
ed1[i].setTextColor(Color.CYAN);
plus[i].setId(i);
plus[i].setHeight(50);
plus[i].setWidth(300);
plus[i].setText("+");
plus[i].setTextColor(Color.BLACK);
minus[i].setId(i);
minus[i].setHeight(50);
minus[i].setWidth(300);
minus[i].setText("-");
minus[i].setTextColor(Color.BLACK);
}
}
}
logcat :-
06-18 04:03:25.657: D/dalvikvm(300): GC_EXTERNAL_ALLOC freed 767 objects / 55840 bytes in 87ms
06-18 04:03:29.057: E/global(300): Deprecated Thread methods are not supported.
06-18 04:03:29.057: E/global(300): java.lang.UnsupportedOperationException
06-18 04:03:29.057: E/global(300): at java.lang.VMThread.stop(VMThread.java:85)
06-18 04:03:29.057: E/global(300): at java.lang.Thread.stop(Thread.java:1379)
06-18 04:03:29.057: E/global(300): at java.lang.Thread.stop(Thread.java:1344)
06-18 04:03:29.057: E/global(300): at com.example.snooder.splash$1.run(splash.java:35)
06-18 04:03:55.678: D/AndroidRuntime(300): Shutting down VM
06-18 04:03:55.678: W/dalvikvm(300): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-18 04:03:55.717: E/AndroidRuntime(300): FATAL EXCEPTION: main
06-18 04:03:55.717: E/AndroidRuntime(300): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.snooder/com.example.snooder.player_name}: java.lang.NumberFormatException: unable to parse 'null' as integer
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.os.Looper.loop(Looper.java:123)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-18 04:03:55.717: E/AndroidRuntime(300): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 04:03:55.717: E/AndroidRuntime(300): at java.lang.reflect.Method.invoke(Method.java:521)
06-18 04:03:55.717: E/AndroidRuntime(300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-18 04:03:55.717: E/AndroidRuntime(300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-18 04:03:55.717: E/AndroidRuntime(300): at dalvik.system.NativeStart.main(Native Method)
06-18 04:03:55.717: E/AndroidRuntime(300): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer
06-18 04:03:55.717: E/AndroidRuntime(300): at java.lang.Integer.parseInt(Integer.java:406)
06-18 04:03:55.717: E/AndroidRuntime(300): at java.lang.Integer.parseInt(Integer.java:382)
06-18 04:03:55.717: E/AndroidRuntime(300): at com.example.snooder.player_name.onCreate(player_name.java:41)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-18 04:03:55.717: E/AndroidRuntime(300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-18 04:03:55.717: E/AndroidRuntime(300): ... 11 more