Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException in notifyDataSetChanged()
    primarykey
    data
    text
    <p>I am trying for last 19 hours to update the <code>listFragment</code> but can't able to get working with <code>notifyDataSetChanged()</code>. I have visited a lot of thread on it but failed to make working it. I have a parent Fragment and inside this I have three <code>ListFragment</code>. The <code>ListFragment</code>s need to pass data among them and I am able to do this via <code>interface</code>. Information are being passed successfully. But the <code>ListView</code> is not updating. This is my trying code:</p> <pre><code>public class SubChaptersListFragment extends SherlockListFragment { ArrayAdapter&lt;String&gt; mAdapter = null; ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int layout = Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1; Chapter instance = CompetitiveProgramming.chapterList.get(0); for (int i = 0; i &lt; instance.subchapterList.size(); i++) { items.add(instance.subchapterList.get(i).subChapterTitle); } mAdapter = new ArrayAdapter&lt;String&gt;(getSherlockActivity(), layout, items); setListAdapter(mAdapter); } @Override public void onStart() { super.onStart(); if (getFragmentManager().findFragmentById( R.id.sub_sub_category_fragment) != null) { getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); } } // this function is invoked from another `fragment` and position is retrieved successfully public void updateList(int position) { Chapter instance = CompetitiveProgramming.chapterList.get(position); items.clear(); for (int i = 0; i &lt; instance.subchapterList.size(); i++) { items.add(instance.subchapterList.get(i).subChapterTitle); } mAdapter.notifyDataSetChanged(); // nullpointerException in this line } } </code></pre> <p><strong>Edit</strong> Logcat</p> <pre><code>08-13 18:33:30.670: E/AndroidRuntime(537): java.lang.NullPointerException 08-13 18:33:30.670: E/AndroidRuntime(537): at me.kaidul.uhunt.SubChaptersListFragment.updateList(SubChaptersListFragment.java:57) 08-13 18:33:30.670: E/AndroidRuntime(537): at me.kaidul.uhunt.CompetitiveProgramming.onChapterSelected(CompetitiveProgramming.java:214) 08-13 18:33:30.670: E/AndroidRuntime(537): at me.kaidul.uhunt.ChaptersListFragment.onListItemClick(ChaptersListFragment.java:60) 08-13 18:33:30.670: E/AndroidRuntime(537): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58) 08-13 18:33:30.670: E/AndroidRuntime(537): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 08-13 18:33:30.670: E/AndroidRuntime(537): at android.widget.ListView.performItemClick(ListView.java:3382) 08-13 18:33:30.670: E/AndroidRuntime(537): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 08-13 18:33:30.670: E/AndroidRuntime(537): at android.os.Handler.handleCallback(Handler.java:587) </code></pre> <p>This is how I called the fragment from parentFragment:</p> <pre><code>@Override public void onChapterSelected(int position) { SubChaptersListFragment subChapterFrag = new SubChaptersListFragment(); if ( subChapterFrag != null) { subChapterFrag.updateList(position); } else { } } </code></pre>
    singulars
    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.
 

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