我正在尝试在我的测试设备Moto G3上创建一个SQLite数据库。我既没有收到任何错误也没有写任何数据。 提一下,我没有SD卡。
这是数据库助手类:
package com.apptree.dingdong.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseUserHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "Dingdong.db";
private static final String TABLE_USER_DATA = "user_data";
// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_EMAIL_ID = "email";
private static final String KEY_NAME = "name";
public DatabaseUserHandler(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Log.d("Snapper"," DatabaseUserHandler created ");
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE " + TABLE_USER_DATA + " ("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_EMAIL_ID + " TEXT,"
+ KEY_NAME + " TEXT" + ");";
db.execSQL(CREATE_TABLE);
Log.d("Snapper"," DatabaseUserHandler onCreate called "+db.getPath().toString());
Log.d("Snapper"," DatabaseUserHandler query "+CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER_DATA);
onCreate(db);
}
public void addUser(UserData user) {
Log.d("Snapper"," User created ");
SQLiteDatabase db = this.getWritableDatabase();
Log.d("Snapper"," DatabaseUserHandler db version "+db.getVersion());
ContentValues values = new ContentValues();
values.put(KEY_NAME, user.getName());
values.put(KEY_EMAIL_ID, user.getEmail());
// Inserting Row
db.insert(TABLE_USER_DATA, null, values);
db.close();
}
}
这里我在一个活动中初始化课程:
当我记录创建数据库的路径时。我得到以下不存在的路径(在Android Devie监视器中检查)。
数据/用户/ 0 / com.d.dingdong /数据库/ Dingdong.db
我缺少什么?