-1

我编写了一个代码来动态创建表格布局和表格行,并从 Web 服务中添加值。它给了我TargetInvocation例外。这可能是什么原因?

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在线上升

   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)
4

1 回答 1

0

您是否在代码中初始化数组deleteuserList....

for您需要在循环之前调用以下行...

deleteuserList = new TextView[deleteuserDetails.size()];
于 2012-12-21T09:40:52.190 回答