2012-12-21 83 views
-1

我編寫了一個代碼來動態創建表格佈局和表格行並添加表單Web服務的值。這是給我TargetInvocation例外。這可能是什麼原因?Android中的IllegalStateException TableLayout

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) 
+0

對不起,我接受我的編輯 –

回答

0

你初始化數組deleteuserList在你的代碼....

您需要調用之前的以下行在for環......

deleteuserList = new TextView[deleteuserDetails.size()]; 
+0

而IAM加入以表格佈局我得到IllegalStateException異常 –

+0

請張貼完整日誌貓... –