int count = 100;
Bundle[] options = new Bundle[count];
public Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
int orderId = Integer.parseInt(flipper.getCurrentView().getTag().toString()) - 1;
switch (msg.what){
case 0:
String optionID = String.valueOf(msg.getData().getInt("optionID"));
int atm_que_id = msg.getData().getInt("atm_que_id");
String optionValue = msg.getData().getString("answer");
int a = options.length;
System.out.println(a);
options[0].putInt("atm_que_id", 1);
options[0].putString(optionID, optionValue);
System.out.println(options[orderId].toString());
break;
case 1:
break;
}
}
};上面的是Activty中一段匿名面部类,count在Activity方法onCreate前定义,在onCreate方法中赋值为100报的错是数值溢出(红色代码)打印出来的a的值为0
将代码改为下面Bundle[] options = new Bundle[100];
public Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
int orderId = Integer.parseInt(flipper.getCurrentView().getTag().toString()) - 1;
switch (msg.what){
case 0:
String optionID = String.valueOf(msg.getData().getInt("optionID"));
int atm_que_id = msg.getData().getInt("atm_que_id");
String optionValue = msg.getData().getString("answer");
int a = options.length;
System.out.println(a);
options[0].putInt("atm_que_id", 1);
options[0].putString(optionID, optionValue);
System.out.println(options[orderId].toString());
break;
case 1:
break;
}
}
};报的错为红色代码行空指针异常。
请给位赐教
public Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
int orderId = Integer.parseInt(flipper.getCurrentView().getTag().toString()) - 1;
switch (msg.what){
case 0:
String optionID = String.valueOf(msg.getData().getInt( "optionID "));
int atm_que_id = msg.getData().getInt( "atm_que_id ");
String optionValue = msg.getData().getString( "answer ");
int a = options.length;
System.out.println(a);
options[0].putInt( "atm_que_id ", 1);
options[0].putString(optionID, optionValue);
System.out.println(options[orderId].toString());
break;
case 1:
break;
}
} }; 上面的是Activty中一段匿名面部类,count在Activity方法onCreate前定义,在onCreate方法中赋值为100报的错是数值溢出(红色代码)打印出来的a的值为0
将代码改为下面 Bundle[] options = new Bundle[100];
public Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
int orderId = Integer.parseInt(flipper.getCurrentView().getTag().toString()) - 1;
switch (msg.what){
case 0:
String optionID = String.valueOf(msg.getData().getInt( "optionID "));
int atm_que_id = msg.getData().getInt( "atm_que_id ");
String optionValue = msg.getData().getString( "answer ");
int a = options.length;
System.out.println(a);
options[0].putInt( "atm_que_id ", 1);
options[0].putString(optionID, optionValue);
System.out.println(options[orderId].toString());
break;
case 1:
break;
}
} }; 报的错为红色代码行空指针异常。
请给位赐教
Bundle[] options = new Bundle[100]; 这句只是定义了一个长度为100的Bundle数组,但是数组里面每一个并没有实例化,换句话来说,每一个bundle对象都是null,你用一个null的对象去调用它的方法,肯定会报错,而且是空指针异常。