0

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();
            }
    }
1
  • mdb is reference of DataBaseManager class which contains code of table creation.. Commented Feb 22, 2012 at 8:05

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

this method is present in class DataBaseManager and I am making object of This class in Resume Method of launching Activity.
Take a look at the Activity Lifecycle. The onResume() method is not invoked until after onCreate(), so that is why mdb is null in the onCreate method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.