can you help me with this one. I don't know why I am getting null pointer exception even I know that the data is exist in the database. What I am trying to do is to access a method in a class, that method is for getting all the information of the given report code in the database. But it keeps on giving me null pointer exception. Here is the method I am referring to:
I am calling the method of different class through this:
S_9th_ISubmit a = new S_9th_ISubmit();
a.Uploading();
This is the method I am calling
public void Uploading() { for (int i = 0; i < Constants.ARRAYLIST_REPORTCODES.size(); i++) { Log.d("size:", String.valueOf(Constants.ARRAYLIST_REPORTCODES.size())); Log.d("content", String.valueOf(Constants.ARRAYLIST_REPORTCODES)); final String code = Constants.ARRAYLIST_REPORTCODES.get(i).toString(); Log.d("Uploading contents of Report Code: ", code); Cursor details = databaseHandler.getHeaderDetails(code); final String infotype = details.getString(details.getColumnIndex(Constants.REPORT_INFOTYPECODE)); String district = details.getString(details.getColumnIndex(Constants.REPORT_DISTRICTCODE)); final String province = details.getString(details.getColumnIndex(Constants.REPORT_PROVINCECODE)); final String date = details.getString(details.getColumnIndex(Constants.REPORT_DATEOBSERVED)); final String competitor = details.getString(details.getColumnIndex(Constants.REPORT_ISCOMPETITOR)); final String remarks = details.getString(details.getColumnIndex(Constants.REPORT_REMARKS));}
Do i need to open the database to access the database.? Below shows my logcat.
09-12 08:43:52.250: E/AndroidRuntime(14919): FATAL EXCEPTION: main
09-12 08:43:52.250: E/AndroidRuntime(14919): java.lang.NullPointerException
09-12 08:43:52.250: E/AndroidRuntime(14919): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
09-12 08:43:52.250: E/AndroidRuntime(14919): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)
09-12 08:43:52.250: E/AndroidRuntime(14919): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:223)
09-12 08:43:52.250: E/AndroidRuntime(14919): at com.dfd.ireport.DatabaseHandler.getHeaderDetails(DatabaseHandler.java:437)
09-12 08:43:52.250: E/AndroidRuntime(14919): at com.dfd.ireport.S_9th_ISubmit.Uploading(S_9th_ISubmit.java:1137)
Here is the code in my databaseHandler
public Cursor getHeaderDetails(String code){
SQLiteDatabase dbSqlite = this.getReadableDatabase();
Cursor c = dbSqlite.query(Constants.TABLE_REPORT, new String[] { Constants.REPORT_ID,
Constants.REPORT_CODE,
Constants.REPORT_INFOTYPECODE,
Constants.REPORT_DISTRICTCODE,
Constants.REPORT_PROVINCECODE,
Constants.REPORT_DATEOBSERVED,
Constants.REPORT_ISCOMPETITOR,
Constants.REPORT_REMARKS}, Constants.REPORT_CODE+"=?", new String[]{code}, null, null, null);
if (c != null) {
c.moveToFirst();
}
dbSqlite.close();
return c;
}
I tried to add this on my Uploading method to access the database but nothing happened.What else do I need to do, how can I check the context that I'm getting?
DatabaseHandler databaseHandler;
databaseHandler = new DatabaseHandler(this);
if (databaseHandler != null)
{
databaseHandler.close();
databaseHandler.createDB();
}
DatabaseHandler.getHeaderDetails()nulltogetHeaderDetails. Log and see what iscode