problem - populate database into listview in android
<p>hi all
i need to populate database elements in listview.  i get null pointer exception and array adapter errors. i did the following ways:
1)created a string array with size of number of rows 2) stored database values in array 3)merge in listview . i tried long time but i cannot find it.
in coding:</p>

<pre><code>    Cursor c = db.rawQuery("select * from stopwatch"  , null);
    if (c != null ) {
    if  (c.moveToFirst()) {
      do {
        counter=counter+1;   // finding no of rows in table.
      }while (c.moveToNext());
    }
    } 
    array=new String[counter];


    counter1=0;
    Cursor c1 = db.rawQuery("select * from stopwatch"  , null);
    if (c1 != null ) {
    if  (c1.moveToFirst()) {
      do {
           array[counter1]=String.valueOf(c1.getInt(0))+":"+String.valueOf(c1.getInt(1))+":"+String.valueOf(c1.getInt(2));
</code></pre>

<p>counter=counter+1;
          }while (c1.moveToNext());
        }
        }
        db.close();</p>

<pre><code>    // populating in listview as follows
     list1.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, array));
</code></pre>

<p>my logcat:</p>

<pre><code>   05-12 18:52:30.853: ERROR/AndroidRuntime(8330): java.lang.NullPointerException
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
   05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.AbsListView.obtainView(AbsListView.java:1254)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1142)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.ListView.onMeasure(ListView.java:1055)
   05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.View.measure(View.java:7117)
   05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2929)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:619)
   05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at  android.widget.LinearLayout.onMeasure(LinearLayout.java:280)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.View.measure(View.java:7117)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2929)
05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.View.measure(View.java:7117)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.View.measure(View.java:7117)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2929)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.View.measure(View.java:7117)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.ViewRoot.performTraversals(ViewRoot.java:713)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1504)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.os.Handler.dispatchMessage(Handler.java:99)
   05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at  android.os.Looper.loop(Looper.java:123)
  05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at android.app.ActivityThread.main(ActivityThread.java:3948)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at java.lang.reflect.Method.invokeNative(Native Method)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at  java.lang.reflect.Method.invoke(Method.java:521)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
 05-12 18:52:30.853: ERROR/AndroidRuntime(8330):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>
