在我的Android应用程序中,SQLIte数据库不能在我的手机上创建,但它在模拟器上正常工作(插入,删除)

时间:2017-09-25 06:20:39

标签: android database sqlite android-sqlite

在模拟器上,一切正常,数据库被创建,表格被创建。我也尝试获取example.db的备份以检查是否创建了数据库,没有得到任何备份文件,但在模拟器上我得到带有条目的example.db的备份。我不知道发生了什么,这是权限问题吗?

我也尝试WRITE_EXTERNAL_STORAGE许可,但没有成功。

请帮帮我,谢谢。

我的日志猫

09-25 11:33:47.100 13608-13608/com.dupat.fund E/SQLiteLog: (1) no such table: m1
09-25 11:33:47.100 13608-13608/com.dupat.fund D/AndroidRuntime: Shutting down VM
09-25 11:33:47.110 13608-13608/com.dupat.fund E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dupat.fund, PID: 13608
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dupat.fund/com.dupat.fund.Members}: android.database.sqlite.SQLiteException: no such table: m1 (code 1): , while compiling: select * from m1
    #################################################################
    Error Code : 1 (SQLITE_ERROR)
    Caused By : SQL(query) error or missing database.
        (no such table: m1 (code 1): , while compiling: select * from m1)
    #################################################################
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
        at android.app.ActivityThread.access$1100(ActivityThread.java:229)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:7325)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
     Caused by: android.database.sqlite.SQLiteException: no such table: m1 (code 1): , while compiling: select * from m1
    #################################################################
    Error Code : 1 (SQLITE_ERROR)
    Caused By : SQL(query) error or missing database.
        (no such table: m1 (code 1): , while compiling: select * from m1)
    #################################################################
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1062)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:627)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
        at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1471)
        at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1410)
        at com.dupat.fund.DatabaseHelper.getAllData(DatabaseHelper.java:145)
        at com.dupat.fund.Members.onStart(Members.java:105)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
        at android.app.Activity.performStart(Activity.java:6943)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3276)
            ... 9 more

我的数据库助手就是这个

public static final String DATABASE_NAME = "example.db";
public static final String TABLE_NAME1 = "m1";

public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, 1);
    SQLiteDatabase db=this.getWritableDatabase();
}


@Override
public void onCreate(SQLiteDatabase db) {

    db.execSQL("create table m1(_ID TEXT PRIMARY KEY, " +
            "NAME TEXT, MOBILE TEXT, SHARE TEXT, AMT TEXT, RATE TEXT, COLLECTOR TEXT, STATUS TEXT, JAMA TEXT, DEFAULTER TEXT)");

    db.execSQL("create table m2(_ID TEXT PRIMARY KEY, " +
            "NAME TEXT, MOBILE TEXT, SHARE TEXT, AMT TEXT, RATE TEXT, COLLECTOR TEXT, STATUS TEXT, JAMA TEXT, DEFAULTER TEXT)");

    db.execSQL("create table m3(_ID TEXT PRIMARY KEY, " +
            "NAME TEXT, MOBILE TEXT, SHARE TEXT, AMT TEXT, RATE TEXT, COLLECTOR TEXT, STATUS TEXT, JAMA TEXT, DEFAULTER TEXT)");
}

0 个答案:

没有答案