Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Anyone please tell where i am wrong?</p> </blockquote> <p>The thing you did wrong in your code is the way you initialize the <code>CharSequence</code> array in the <code>getEntries</code> method. Your code:</p> <pre><code>if (cursor.moveToFirst()){ int i=0; do{ size[i]=new String(cursor.getString(1)+"X"+cursor.getString(2)); System.out.println(cursor.getString(1)+"X"+cursor.getString(2)); }while(cursor.moveToNext()); } </code></pre> <p>You initialize the <code>size</code> array with the size of the <code>Cursor</code> and then you go in to the while loop above. The problem is that your while loop only sets the value for <code>i = 0</code> as you don't increase <code>i</code>'s value in that loop. For this reason your <code>size</code> array will have a value only for position <code>0</code> and <code>null</code> on all other positions. This will make the <code>ArrayAdapter</code> throw that <code>NullPointerException</code>.</p> <p>The correct loop would be:</p> <pre><code>if (cursor.moveToFirst()){ int i=0; do{ size[i]=new String(cursor.getString(1)+"X"+cursor.getString(2)); System.out.println(cursor.getString(1)+"X"+cursor.getString(2)); i++; }while(cursor.moveToNext()); } </code></pre> <p>The full <code>getEntries</code> method would be:</p> <pre><code>private CharSequence[] getEntries() { Cursor cursor = SQLiteAdapter.queueAll(); int num = cursor.getCount(); String[] size = new String[num]; System.out.println(cursor.getCount()); if (cursor.moveToFirst()) { int i = 0; do { size[i] = new String(cursor.getString(1) + "X" + cursor.getString(2)); i++; } while (cursor.moveToNext()); } cursor.close(); return size; } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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