Note that there are some explanatory texts on larger screens.

plurals
  1. POlayout nullpointerexception in asynctask
    primarykey
    data
    text
    <p>I am updating my fragments ui's from onPostExecute running on the ui thread. I have a nullpointerException within my <code>onPostExecute()</code> asynctask method.</p> <p>Here is what is within my method:</p> <pre><code>// dismiss the dialog after getting all products pDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { public void run() { //TODO fill front-end //all //get view for each fragment. for(int i = 0; i&lt; 3; i++){ Fragment fragment = getSupportFragmentManager().findFragmentByTag("android:switcher:" + mViewPager.getId() + ":" + i); View view = fragment.getView(); TableLayout layout; switch(i){ /* Update parsed JSON data into tablelayouts */ case 0: //allcontent layout = (TableLayout) view.findViewById(R.id.AllContentLayout); for(JsonInObject item: allItems){ if(item.getType().equals("text")){ addText(layout, item); }else{ addImage(layout, item); } } break; case 1: //Error take place within this from this for loop. //text layout = (TableLayout) view.findViewById(R.id.TextContentLayout); for(Textobj item: textBlocks){ addText(layout, item); } break; case 2: //images layout = (TableLayout) view.findViewById(R.id.ImageContentLayout); for(Imageobj item: images){ addImage(layout, item); } break; default: break; } } } }); </code></pre> <p>This is the addText method stated within the error:</p> <pre><code> private void addText(TableLayout textLayout, JsonInObject item){ //build the rows and add them to the fragment view //TableRow newrow = (TableRow) findViewById(R.id.tableTextRow); TableRow newrow = new TableRow(ContentActivity.this); newrow.setLayoutParams(new TableLayout.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); TextView nameText = new TextView(ContentActivity.this); nameText.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); //TextView nametext = (TextView) findViewById(R.id.name); if(item.setIsComplete() != false){ try{ nameText.setText(item.getData()); } catch(NullPointerException e){ Log.println(1, "NULLPOINTER", "Either the tablerow, Texview or tablelayout is null... for some reason."); e.printStackTrace(); return; } newrow.addView(nameText); textLayout.addView(newrow); } } </code></pre> <p>Here is my error:</p> <pre><code>10-19 11:39:36.706: E/AndroidRuntime(32637): FATAL EXCEPTION: main 10-19 11:39:36.706: E/AndroidRuntime(32637): java.lang.NullPointerException 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.eddiecubed44.Jsonapptest.ContentActivity.addText(ContentActivity.java:448) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.eddiecubed44.Jsonapptest.ContentActivity.access$3(ContentActivity.java:426) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.eddiecubed44.Jsonapptest.ContentActivity$LoadTextnImgs$1.run(FuzzContentActivity.java:355) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.app.Activity.runOnUiThread(Activity.java:4631) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.eddiecubed44.Jsonapptest.ContentActivity$LoadTextnImgs.onPostExecute(ContentActivity.java:318) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.eddiecubed44.Jsonapptest.ContentActivity$LoadTextnImgs.onPostExecute(ContentActivity.java:1) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.os.AsyncTask.finish(AsyncTask.java:631) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.os.AsyncTask.access$600(AsyncTask.java:177) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.os.Handler.dispatchMessage(Handler.java:99) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.os.Looper.loop(Looper.java:137) 10-19 11:39:36.706: E/AndroidRuntime(32637): at android.app.ActivityThread.main(ActivityThread.java:4918) 10-19 11:39:36.706: E/AndroidRuntime(32637): at java.lang.reflect.Method.invokeNative(Native Method) 10-19 11:39:36.706: E/AndroidRuntime(32637): at java.lang.reflect.Method.invoke(Method.java:511) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004) 10-19 11:39:36.706: E/AndroidRuntime(32637): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) 10-19 11:39:36.706: E/AndroidRuntime(32637): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>The nullpointer is associated with he layout that i am using to add the tablerows to. I am at a loss why this is turning null. The line number that the error is happening on is within <code>case 1:</code> And as you can see, I have used the layout before in <code>case 0:</code> and I am assuming that the rows were added correctly.</p> <p>help me obi wan kenobi you're my only hope.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload