本文介绍了IllegalStateException异常Android中TableLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个code动态创建表格布局和表行,并添加值形式的Web服务。这是给我的 TargetInvocation
例外。可能是什么原因呢?
保护无效onPostExecute(最终的ArrayList< DeleteuserDetails> deleteuserDetails){ 的for(int i = 0; I< = deleteuserDetails.size();我++){ 的TableRow deleteUserRow =新的TableRow(Deleteuser.this);
deleteUserRow.setId(ⅰ);
deleteUserRow.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
复选框select_id =新的复选框(Deleteuser.this);
select_id.setId(ⅰ);
deleteUserRow.addView(select_id);
deleteuserList [I] =新的TextView(Deleteuser.this);
deleteuserList [I] .setId(ⅰ);
deleteuserList [I] .setText(deleteuserDetails.get(ⅰ).getUserId());
deleteUserRow.addView(deleteuserList [I]);
的uname =新的TextView(Deleteuser.this);
uName.setId(ⅰ);
uName.setText(deleteuserDetails.get(ⅰ).getUserName());
deleteUserRow.addView(UNAME);
UserRole的=新的TextView(Deleteuser.this);
Userrole.setId(ⅰ);
Userrole.setText(deleteuserDetails.get(ⅰ).getUserRole());
deleteUserRow.addView(UserRole的);
CreatedDate =新的TextView(Deleteuser.this);
CreatedDate.setId(ⅰ);
CreatedDate.setText(deleteuserDetails.get(ⅰ).getCreatedDate());
deleteUserRow.addView(CreatedDate);
CreatedBy =新的TextView(Deleteuser.this);
CreatedBy.setId(ⅰ);
CreatedBy.setText(deleteuserDetails.get(ⅰ).getCreatedBy());
deleteUserRow.addView(CreatedBy);
userdetailTable.addView(deleteUserRow,新TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
select_id.setTag(ⅰ);
select_id.setOnClickListener(监听);
}
的TableRow deleteUserRow1 =新的TableRow(Deleteuser.this);
deleteUserRow1.setId(100);
deleteUserRow1.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
按钮btn_user_delete =新按钮(Deleteuser.this);
btn_user_delete.setText(删除);
deleteUserRow1.addView(btn_user_delete);
btn_user_delete.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
新DeleteUserid()执行(为CheckedValue);
}
});
}
IllegalStateException异常
上升在该行
userdetailTable.addView(deleteUserRow,新TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
的logcat
15 12-21:05:44.630:E / AndroidRuntime(644):显示java.lang.NullPointerException
12-21 15:05:44.630:E / AndroidRuntime(644):在com.mvss.admin.Deleteuser $ deteUserIdLoad.onPostExecute(Deleteuser.java:123)
12-21 15:05:44.630:E / AndroidRuntime(644):在com.mvss.admin.Deleteuser $ deteUserIdLoad.onPostExecute(Deleteuser.java:1)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.os.AsyncTask.finish(AsyncTask.java:417)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.os.AsyncTask.access $ 300(AsyncTask.java:127)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:429)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.os.Handler.dispatchMessage(Handler.java:99)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.os.Looper.loop(Looper.java:123)
12-21 15:05:44.630:E / AndroidRuntime(644):在android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:05:44.630:E / AndroidRuntime(644):在java.lang.reflect.Method.invokeNative(本机方法)
12-21 15:05:44.630:E / AndroidRuntime(644):在java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:05:44.630:E / AndroidRuntime(644):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 15:05:44.630:E / AndroidRuntime(644):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-21 15:05:44.630:E / AndroidRuntime(644):在dalvik.system.NativeStart.main(本机方法)
解决方案
您在初始化你的阵列 deleteuserList
code ....
您需要调用为
循环之前以下行...
deleteuserList =新的TextView [deleteuserDetails.size()];
I wrote a code to create table layout and table rows dynamically and add the values form web service. It is giving me TargetInvocation
exception. What could be the reason for this?
protected void onPostExecute(final ArrayList<DeleteuserDetails>deleteuserDetails) {
for(int i=0;i<=deleteuserDetails.size();i++){
TableRow deleteUserRow=new TableRow(Deleteuser.this);
deleteUserRow.setId(i);
deleteUserRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
CheckBox select_id = new CheckBox(Deleteuser.this);
select_id.setId(i);
deleteUserRow.addView(select_id);
deleteuserList[i]=new TextView(Deleteuser.this);
deleteuserList[i].setId(i);
deleteuserList[i].setText(deleteuserDetails.get(i).getUserId());
deleteUserRow.addView(deleteuserList[i]);
uName=new TextView(Deleteuser.this);
uName.setId(i);
uName.setText(deleteuserDetails.get(i).getUserName());
deleteUserRow.addView(uName);
Userrole=new TextView(Deleteuser.this);
Userrole.setId(i);
Userrole.setText(deleteuserDetails.get(i).getUserRole());
deleteUserRow.addView(Userrole);
CreatedDate=new TextView(Deleteuser.this);
CreatedDate.setId(i);
CreatedDate.setText(deleteuserDetails.get(i).getCreatedDate());
deleteUserRow.addView(CreatedDate);
CreatedBy=new TextView(Deleteuser.this);
CreatedBy.setId(i);
CreatedBy.setText(deleteuserDetails.get(i).getCreatedBy());
deleteUserRow.addView(CreatedBy);
userdetailTable.addView(deleteUserRow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
select_id.setTag(i);
select_id.setOnClickListener(listener);
}
TableRow deleteUserRow1=new TableRow(Deleteuser.this);
deleteUserRow1.setId(100);
deleteUserRow1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
Button btn_user_delete=new Button(Deleteuser.this);
btn_user_delete.setText("Delete");
deleteUserRow1.addView(btn_user_delete);
btn_user_delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DeleteUserid().execute(checkedValue);
}
});
}
IllegalStateException
rises at the line
userdetailTable.addView(deleteUserRow,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
LOGCAT
12-21 15:05:44.630: E/AndroidRuntime(644): java.lang.NullPointerException
12-21 15:05:44.630: E/AndroidRuntime(644): at com.mvss.admin.Deleteuser$deteUserIdLoad.onPostExecute(Deleteuser.java:123)
12-21 15:05:44.630: E/AndroidRuntime(644): at com.mvss.admin.Deleteuser$deteUserIdLoad.onPostExecute(Deleteuser.java:1)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.os.AsyncTask.finish(AsyncTask.java:417)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.os.AsyncTask.access$300(AsyncTask.java:127)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.os.Looper.loop(Looper.java:123)
12-21 15:05:44.630: E/AndroidRuntime(644): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:05:44.630: E/AndroidRuntime(644): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:05:44.630: E/AndroidRuntime(644): at java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:05:44.630: E/AndroidRuntime(644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 15:05:44.630: E/AndroidRuntime(644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-21 15:05:44.630: E/AndroidRuntime(644): at dalvik.system.NativeStart.main(Native Method)
解决方案
Are you initializing the Array deleteuserList
in you code....
You need to call the following line before the for
loop...
deleteuserList = new TextView[deleteuserDetails.size()];
这篇关于IllegalStateException异常Android中TableLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!