虽然从非活性类访问SQLite的,越来越NullPointerException
NullPointerException异常,同时访问非活动类的SQLite
文件 - >SessionDB.java
public class SessionDB {
private SQLiteDatabase database;
private SQLiteHelper dbHelper;
private String[] allColumns = { SQLiteHelper.SESSION_ID,
SQLiteHelper.SESSION_STRING };
public SessionDB(Context context) {
dbHelper = new SQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void createSession(String session_string) {
ContentValues values = new ContentValues();
values.put(SQLiteHelper.SESSION_STRING, session_string);
database.insert(SQLiteHelper.SESSION_TABLE, null, values); // NullPointerException Here
}
}
文件 - >Live.java
public class Live {
protected Context context;
public Live(Context context) {
this.context = context;
}
public accessOK {
SessionDB ses = new SessionDB(context);
ses.createSession("Sample"); // NullPointerException
}
}
那么,什么sh应该做到这一点的最佳方式?
这应该被添加为注释。不是一个答案 – Raghunandan 2013-05-11 14:32:31
好吧,我已经把它改写成一个声明。 – reavowed 2013-05-11 14:34:26
即使现在这应该被添加为评论。没有足够的细节将其作为答案发布。添加更多的细节或一些代码片段。 – Raghunandan 2013-05-11 14:35:39