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;
}
}
};报的错为红色代码行空指针异常。
请给位赐教
解决方案 »
- 求一个android sdk 下载地址
- 怎么获取手机上保存的wifi密码?
- GridView中获取ImageView的问题????sImageView = (ImageView) arg0.getItemAtPosition(arg2)
- 如何隐藏gridView的滚动条
- 请教一个关于GPS实时获取的问题!!
- android Activity之间的过渡界面?
- JNI惹的祸?
- 自己开发的医药健康API接口,求APP开发者建议
- 如何使用百度云 API 推送富媒体消息,百度推送的富媒体发送官方接口是什么?
- Android String不能转化为int
- contentprovider中如何更新单条数据
- 关于OpenGL_ES的点击问题
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的对象去调用它的方法,肯定会报错,而且是空指针异常。