Note that there are some explanatory texts on larger screens.

plurals
  1. POListView throws NULL Pointer exception
    primarykey
    data
    text
    <p>read a lot of the questions about NPE's.. still in the dark.</p> <p>I declare a listview :</p> <pre><code>public class SelecteerKernen extends Activity { protected WoordData kerndata; public ListView listView = null; </code></pre> <p>Later, I fill it with data from a SQLite dBase. This works.</p> <pre><code>// Fill Listview with the kern-names ListView listView = (ListView) findViewById(R.id.kernenlist); listView.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_multiple_choice, al)); </code></pre> <p>But then, when I want to count the items, to save the checked items to preferences, I get a NPE on the int count = ... line of this code .</p> <p>Edit I solved the count.. line, now the if (this.listView)... line throws the NPE.. Argh! :</p> <pre><code> private String getSavedItems() { String savedItems = ""; int count = this.listView.getAdapter().getCount(); for (int i = 0; i &lt; count; i++) { //edit now THIS line trows the NPE : if (this.listView.isItemChecked(i)) { if (savedItems.length() &gt; 0) { savedItems += "," + this.listView.getItemAtPosition(i); } else { savedItems += this.listView.getItemAtPosition(i); } } } return savedItems; </code></pre> <p>Thanks for the help!!</p> <hr> <p>PS. I noticed that users are asked for LogCats. How can that help to find the error? Here's mine :</p> <blockquote> <p>11-01 19:42:35.680: W/dalvikvm(28146): threadid=1: thread exiting with uncaught exception (group=0x40015560) 11-01 19:42:35.700: E/AndroidRuntime(28146): FATAL EXCEPTION: main 11-01 19:42:35.700: E/AndroidRuntime(28146): java.lang.NullPointerException 11-01 19:42:35.700: E/AndroidRuntime(28146): at happyworx.nl.Flitswoorden.SelecteerKernen.getSavedItems(SelecteerKernen.java:163) 11-01 19:42:35.700: E/AndroidRuntime(28146): at happyworx.nl.Flitswoorden.SelecteerKernen.SavePreferences(SelecteerKernen.java:121) 11-01 19:42:35.700: E/AndroidRuntime(28146): at happyworx.nl.Flitswoorden.SelecteerKernen.access$0(SelecteerKernen.java:115) 11-01 19:42:35.700: E/AndroidRuntime(28146): at happyworx.nl.Flitswoorden.SelecteerKernen$1.onClick(SelecteerKernen.java:72) ...</p> </blockquote>
    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