我通过以下方式调用不同类的方法:
S_9th_ISubmit a = new S_9th_ISubmit();
a.Uploading();
这是我打电话的方法
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));
}
我是否需要打开数据库才能访问数据库。下面显示了我的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)
这是我的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;
}
我尝试在我的Uploading方法上添加这个来访问数据库但没有发生任何事情。我还需要做什么,如何检查我得到的上下文?
DatabaseHandler databaseHandler;
databaseHandler = new DatabaseHandler(this);
if (databaseHandler != null)
{
databaseHandler.close();
databaseHandler.createDB();
}
答案 0 :(得分:3)
我的猜测在SQLiteDatabase dbSqlite = this.getReadableDatabase();
,dbSqlite为空!
getReadableDatabase()返回null,因为您传递的是错误的上下文
尝试检查你传递的上下文。
答案 1 :(得分:0)
Cursor details = databaseHandler.getHeaderDetails(code)show null point。
问题是databaseHandler为null,您可以使用
进行检查Cursor details;
if(databaseHandler != null){
details = databaseHandler.getHeaderDetails(code);
}else{
Log.e(" databaseHandler : " ," databaseHandler == null");
}
如果getHeaderDetails()中的问题,logcat将显示导致零点异常的代码行,但我没看到