Sandeep Tiwari
Sandeep Tiwari

Reputation: 2072

Sqlite Query produce Nullpointer Exception?

why SqlLite query in android produce Nullpointer exception I am using this code

public void onCreate(SQLiteDatabase db)
    {
   String newTableQueryString = "create table " +TABLE_NAME +" (" +
                                    TABLE_ROW_ID + " integer primary key autoincrement not null," +
                                    TABLE_ROW_ONE + " text," +
                                    TABLE_ROW_TWO + " text" +
                                    ");";
Log.e("check","table have been created"+newTableQueryString);
        try{

            mdb.execSQL(newTableQueryString);//it produce exce[ption
        }catch(Exception e)
        {
            Log.e("Exception"," "+ e.getMessage());
             e.printStackTrace();
            }
    }

Upvotes: 0

Views: 233

Answers (1)

Mike Bockus
Mike Bockus

Reputation: 2079

My guess is mdb is null when you call:

 mdb.execSQL(newTableQueryString);

Did you mean to invoke the execSQL method on the db method parameter that you're passing into the onCreate method?

Upvotes: 1

Related Questions