SQLite + setAdapter = NPE
<p>There is a NPE at the last line, I can't figure out where it's coming from. Any ideas?</p>

<pre><code>  mySQLiteAdapter = new SQLiteAdapter(this);
  mySQLiteAdapter.openToRead();
  listContent = (ListView)findViewById(R.id.contentlist);
  Cursor cursor = mySQLiteAdapter.queueAll();
  startManagingCursor(cursor);

  String[] from = new String[]{SQLiteAdapter.KEY_CHOICE,         
  SQLiteAdapter.KEY_AMOUNT};
  int[] to = new int[]{R.id.txtChoice, R.id.txtAmtSpent};

  SimpleCursorAdapter cursorAdapter =
   new SimpleCursorAdapter(this, R.layout.row2, cursor, from, to);
  mySQLiteAdapter.close();
  listContent.setAdapter(cursorAdapter);
</code></pre>

<p>HERE IS THE ERROR</p>

<pre><code>    06-19 01:27:50.832: ERROR/AndroidRuntime(1425): FATAL EXCEPTION: main
06-19 01:27:50.832: ERROR/AndroidRuntime(1425): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whycom.idontknow/com.whycom.idontknow.ListSpent}: java.lang.NullPointerException
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.os.Looper.loop(Looper.java:123)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at java.lang.reflect.Method.invokeNative(Native Method)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at java.lang.reflect.Method.invoke(Method.java:521)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at dalvik.system.NativeStart.main(Native Method)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425): Caused by: java.lang.NullPointerException
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at com.whycom.idontknow.ListSpent.makeList(ListSpent.java:161)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at com.whycom.idontknow.ListSpent.onCreate(ListSpent.java:79)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-19 01:27:50.832: ERROR/AndroidRuntime(1425):     ... 11 more
</code></pre>

<p>The whole code is below:</p>

<pre><code> package com.whycom.idontknow;
import java.util.Collections; 
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ListSpent extends ListActivity {
    private SQLiteAdapter mySQLiteAdapter;
    //Intent splat;
    //Bundle b;

    //  String[] amounts;
    //  String[] expenditureArray;
    String choice; 
    String amount; 
    int count;
    String[] dataAry= new String[100];
    //String[] choices;
    String Count;
    SharedPreferences prefs; 
    TextView txtAmtSpent;
    TextView txtChoice;
    ListAdapter adapter;
    ListView listContent;
    int j;
//  ListView listContent;


    //      PreferenceManager.getDefaultSharedPreferences(this);


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainlist);

        prefs = PreferenceManager.getDefaultSharedPreferences(this);
        //ListView listContent = (ListView)findViewById(R.id.contentlist);
        initVars();
        try {
            buildArray();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        makeList();
    }
    static class ViewHolder{
        TextView text;
        TextView button;
    }



    public void buildArray() throws IOException{
        //ArrayList&lt;String&gt; al = new ArrayList&lt;String&gt;(); 

        InputStream instream;
        try {
            instream = openFileInput("mySpends.txt");
            InputStreamReader inputreader = new InputStreamReader(instream);
            BufferedReader buffreader = new BufferedReader(inputreader);

            Count = prefs.getString("Count" , "0");
            count = Integer.parseInt(Count);





            for (int i = 0; i &lt; ((count)*2); i=i+2){
                choice = buffreader.readLine();
                amount = buffreader.readLine();
                dataAry[i] = choice;
                dataAry[i+1] = amount;
                //trial

            }


        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();

        }
    }

    private void initVars(){

        txtAmtSpent = (TextView)findViewById(R.id.txtAmtSpent);
        txtChoice = (TextView)findViewById(R.id.txtChoice);
        listContent = (ListView)findViewById(R.id.contentlist);

    }


    private void makeList(){
         mySQLiteAdapter = new SQLiteAdapter(this);
          mySQLiteAdapter.openToWrite();
          mySQLiteAdapter.deleteAll();
        ListView listContent = (ListView)findViewById(R.id.contentlist);
        String [] dataAryArray = new String[(count)*2];
        j = 0;
        int ind = (count)*2-1;
        for (int i = -1; i &lt; ind; ind = ind - 2){
            dataAryArray[j] = dataAry[ind];
            dataAryArray[j+1] = dataAry[ind-1];

              mySQLiteAdapter.insert(dataAryArray[j],dataAryArray[j+1]);

            j=j+2;


        }
         mySQLiteAdapter.close();

          mySQLiteAdapter.openToRead();
          Cursor cursor = mySQLiteAdapter.queueAll();
          startManagingCursor(cursor);
          String c=SQLiteAdapter.KEY_CHOICE;
          String a=SQLiteAdapter.KEY_AMOUNT;
          String[] from = new String[]{SQLiteAdapter.KEY_CHOICE, SQLiteAdapter.KEY_AMOUNT};
          int[] to = new int[]{R.id.txtChoice, R.id.txtAmtSpent};

          SimpleCursorAdapter cursorAdapter =
           new SimpleCursorAdapter(this, R.id.text, cursor, from, to);

          listContent.setAdapter(cursorAdapter);
          mySQLiteAdapter.close();






        //      adapter = new ArrayAdapter&lt;String&gt;(this, 
        //              android.R.layout.simple_list_item_1, dataAryArray);
        //      setListAdapter(adapter);            
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                    int position, long id) {
                //       When clicked, show a toast with the TextView text
                //              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                //                      Toast.LENGTH_SHORT).show();
                Toast.makeText(getApplicationContext(), "Toast",
                        Toast.LENGTH_SHORT).show();
            }
        }
        )
        ;
    }

}
</code></pre>

<p>Here is the XML named mainlist.xml:</p>

<pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       &gt;
     &lt;TextView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="@string/hello"
       /&gt;
     &lt;ListView
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"/&gt;
     &lt;/LinearLayout&gt;
</code></pre>
