gpt4 book ai didi

android - 尝试在 android 中访问 SQLite 数据库时如何修复 SQLiteOpenHelper.getDatabaseLocked 错误?

转载 作者:行者123 更新时间:2023-11-30 03:04:46 25 4
gpt4 key购买 nike

我正在尝试从 Sqlite 数据库中检索一些数据。但是当我尝试使用 getTaskSent 方法检索数据时,出现以下错误。谁能建议我解决以下错误?

  E/AndroidRuntime(23159):  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)

这是我的数据库代码:

public class Databasehandler extends SQLiteOpenHelper{
private static final String LOGCAT = null;

public Databasehandler(Context applicationcontext) {
super(applicationcontext,"androidsqlite.db", null, 4);
// TODO Auto-generated constructor stub
Log.d(LOGCAT,"Database Created");

}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String query,query1,query2;
query = "CREATE TABLE userlogin ( phoneId INTEGER PRIMARY KEY,username TEXT,userid INTEGER,contacts TEXT UNIQUE)";
query1 = "CREATE TABLE task ( TaskId INTEGER PRIMARY KEY,heading TEXT,desc TEXT,d1 TEXT,d2 TEXT,t1 TEXT,t2 TEXT,receiver TEXT,sender TEXT)";
query2 = "CREATE TABLE me ( fbId INTEGER PRIMARY KEY,fbname TEXT,fbuserid INTEGER,fbpic BLOB,ph TEXT,email TEXT)";
db.execSQL(query1);
db.execSQL(query);
db.execSQL(query2);

}
public void inserttask(HashMap<String, String> queryValues) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values2 = new ContentValues();
values2.put("heading", queryValues.get("heading"));
values2.put("desc", queryValues.get("desc"));
values2.put("d1", queryValues.get("d1"));
values2.put("d2", queryValues.get("d2"));
values2.put("t1", queryValues.get("t1"));
values2.put("t2", queryValues.get("t2"));
values2.put("sender", queryValues.get("sender"));
values2.put("receiver", queryValues.get("receiver"));

database.insert("task", null, values2);
database.close();
}
public ArrayList<HashMap<String, String>> getTaskSent() {
ArrayList<HashMap<String, String>> wordList;
wordList = new ArrayList<HashMap<String, String>>();
String selectQuery = "SELECT * FROM task";

SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> map = new HashMap<String, String>();
//map.put("userid", cursor.getString(1));
map.put("heading", cursor.getString(1));
map.put("desc", cursor.getString(2));
map.put("d1", cursor.getString(3));
map.put("d2", cursor.getString(4));
map.put("t1", cursor.getString(5));
map.put("t2", cursor.getString(6));
map.put("receiver", cursor.getString(7));

wordList.add(map);
} while (cursor.moveToNext());
}cursor.close();
database.close();


return wordList;
}

最佳答案

您传递给Databasehandler 构造函数的Contextnull

关于android - 尝试在 android 中访问 SQLite 数据库时如何修复 SQLiteOpenHelper.getDatabaseLocked 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21985696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com