Unable to substantiate activity ComponentInfo - Null Pointer Exception
<p>I have spent the day trying to fathom this one out (needless to say I am a long way down the learnign curve - hence my need to ask for help!) - below is a simple database program (I'm trying to understand how they work to implement into another app i am working on).</p>

<p>When I click the 'Show' Button - i get the following Run Time Error:</p>

<p>Log Cat</p>

<pre><code>03-14 16:13:39.612: ERROR/AndroidRuntime(341): FATAL EXCEPTION: main
03-14 16:13:39.612: ERROR/AndroidRuntime(341): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.dbtest/com.android.dbtest.ShowActivity}: java.lang.NullPointerException
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.os.Looper.loop(Looper.java:123)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.main(ActivityThread.java:3647)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at java.lang.reflect.Method.invokeNative(Native Method)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at java.lang.reflect.Method.invoke(Method.java:507)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at dalvik.system.NativeStart.main(Native Method)
03-14 16:13:39.612: ERROR/AndroidRuntime(341): Caused by: java.lang.NullPointerException
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.Activity.findViewById(Activity.java:1647)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at com.android.dbtest.ShowActivity.&lt;init&gt;(ShowActivity.java:12)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at java.lang.Class.newInstanceImpl(Native Method)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at java.lang.Class.newInstance(Class.java:1409)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
03-14 16:13:39.612: ERROR/AndroidRuntime(341):     ... 11 more
</code></pre>

<p>My Main activity:</p>

<pre><code>package com.android.dbtest;




import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;


public class DatabaseTestActivity extends Activity {
/** Called when the activity is first created. */


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


    }

    public void handleClick(View v){
        Intent intent = new Intent();
        intent.setClass(this, AddActivity.class);
        startActivity(intent);
    }

    public void showHandleClick(View v){
        Intent intent = new Intent();
        intent.setClass(this, ShowActivity.class);
        startActivity(intent);
    }
    }
</code></pre>

<p>My Show Activity (this is where i think the main error (guessing more than one) probably lies, as it is when i press the show button , that the runtime error occurs, i believe it is related to building the List):</p>

<pre><code>package com.android.dbtest;

import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.util.Log;

public class ShowActivity extends DatabaseTestActivity{

private SQLiteAdapter mySQLiteAdapter;
ListView listContent = (ListView)findViewById(R.id.contentlist);

//TextView listContent = (TextView) findViewById(R.id.contentlist);

SimpleCursorAdapter cursorAdapter;
String cursor;

public static final String LOG_TAG = "dbtest";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show);
    // TODO Auto-generated method stub

    Log.v(LOG_TAG,  "step 1");


    //output.setText(String.valueOf( WHAT I GET FROM DATABASE));


    mySQLiteAdapter = new SQLiteAdapter(this);
    mySQLiteAdapter.openToRead();

    Cursor cursor = mySQLiteAdapter.queueAll();
    startManagingCursor(cursor);
    String[] from = new String[]{SQLiteAdapter.KEY_CONTENT};
    int[] to = new int[] {R.id.text};

    Log.v(LOG_TAG, "from value:" + from );
    Log.v(LOG_TAG, "to value:" + to );

    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
    listContent.setAdapter(cursorAdapter);

    mySQLiteAdapter.close();

}
}
</code></pre>

<p>My SQLiteAdapter:</p>

<pre><code>package com.android.dbtest;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class SQLiteAdapter { 
public static final String MYDATABASE_NAME = "MY_DATABASE"; 
public static final String MYDATABASE_TABLE = "MY_TABLE";
public static final int MYDATABASE_VERSION = 1; 
public static final String KEY_CONTENT = "Content"; 
public static final String KEY_ID = "_id";          //primary key


//create table MY_DATABASE (ID integer primary key, Content text not null); 
private static final String SCRIPT_CREATE_DATABASE =  "create table " 
+ MYDATABASE_TABLE + " (" 
+ KEY_ID + " integer primary key autoincrement, "           
+ KEY_CONTENT + " text not null "  +
        ");"; 

private SQLiteHelper sqLiteHelper; 
private SQLiteDatabase sqLiteDatabase;
private Context context;  
public SQLiteAdapter(Context c)
{  
    context = c;
}  

public SQLiteAdapter openToRead() throws android.database.SQLException 
{ 
    sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION); 
    sqLiteDatabase = sqLiteHelper.getReadableDatabase();
    return this; 
} 
public SQLiteAdapter openToWrite() throws android.database.SQLException {
    sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
    sqLiteDatabase = sqLiteHelper.getWritableDatabase();  return this;
    }
public void close(){ 
    sqLiteHelper.close();
    } 
public long insert(String content){
    ContentValues contentValues = new ContentValues();
    contentValues.put(KEY_CONTENT, content); 
    return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
    }  

public int deleteAll(){ 
    return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null); 
    } 



public Cursor queueAll(){
    String[] columns = new String[]{KEY_ID, KEY_CONTENT};
    Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns,     null, null, null, null, null); 
    return cursor;
}


public class SQLiteHelper extends SQLiteOpenHelper 
{  
    public SQLiteHelper(Context context, String name,    CursorFactory factory, int version) 
    {  
        super(context, name, factory, version); 
        }
    @Override  public void onCreate(SQLiteDatabase db)
    {   
        // TODO Auto-generated method stub 
        db.execSQL(SCRIPT_CREATE_DATABASE); 
        } 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {  
        // TODO Auto-generated method stub  } } }
}
}
}
</code></pre>

<p>finally the XML file for Show:</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_height="wrap_content" 
   android:text="TextView" 
   android:textAppearance="?android:attr/textAppearanceLarge" 
   android:layout_width="wrap_content" 
   android:id="@+id/textView1"&gt;&lt;/TextView&gt;    

   &lt;ListView android:id="@android:id/android:list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"/&gt;

 &lt;/LinearLayout&gt;
</code></pre>
