没有这样的表在sqlite android中找到异常

时间:2016-09-21 11:22:00

标签: android database sqlite

**这是我的错误日志**

09-21 10:49:43.698 24911-24911/com.arkinfosft.mediplus E/SQLiteDatabase: Error inserting Patient_name=dth Patient_contact= Patient_Country=India Patient_email= User_Id=5071 Patient_address= Reg_Date=/Date(1474088400000)/ Patient_state=Gujrat Patient_city=Ahemedabad Patient_photo=photo
                                                                         android.database.sqlite.SQLiteException: no such table: patient_master (code 1): , while compiling: INSERT INTO patient_master(Patient_name,Patient_contact,Patient_Country,Patient_email,User_Id,Patient_address,Reg_Date,Patient_state,Patient_city,Patient_photo) VALUES (?,?,?,?,?,?,?,?,?,?)
                                                                             at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                             at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
                                                                             at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
                                                                             at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                             at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                             at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                                                                             at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
                                                                             at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
                                                                             at com.arkinfosft.mediplus.db.DBHelperDatabaseClass.insertPatientMaster(DBHelperDatabaseClass.java:237)
                                                                             at com.arkinfosft.mediplus.ui.patient.PatientActivity.onConnnectionManagerTaskComplete(PatientActivity.java:335)
                                                                             at com.arkinfosft.mediplus.services.ConnectionManagerTask.onPostExecute(ConnectionManagerTask.java:60)
                                                                             at com.arkinfosft.mediplus.services.ConnectionManagerTask.onPostExecute(ConnectionManagerTask.java:27)
                                                                             at android.os.AsyncTask.finish(AsyncTask.java:631)
                                                                             at android.os.AsyncTask.access$600(AsyncTask.java:177)
                                                                             at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                             at android.os.Looper.loop(Looper.java:137)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:511)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                             at dalvik.system.NativeStart.main(Native Method)

****这是DBhelper类****

public static synchronized DBHelperDatabaseClass getInstance(Context context) {
    // Use the application context, which will ensure that you
    // don't accidentally leak an Activity's context.   
    if (sInstance == null) {
        sInstance = new DBHelperDatabaseClass(context.getApplicationContext());
    }
    return sInstance;
}
public DBHelperDatabaseClass(Context context) {
    super(context, DATABASE_NAME_, null, DATABASE_VERSION);
}
@Override
public void onConfigure(SQLiteDatabase db) {
    super.onConfigure(db);
    db.setForeignKeyConstraintsEnabled(true);
}

@Override
public void onCreate(SQLiteDatabase db) {

    String patientMasterTable = "CREATE TABLE `patient_master` (" +
            "`Patient_Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
            " `Patient_state` TEXT," +
            " `Patient_photo` TEXT," +
            " `Patient_email` TEXT," +
            " `Patient_name` TEXT," +
            " `Patient_Country` TEXT, " +
            "`Patient_address` TEXT, " +
            "` Reg_Date` NUMERIC, " +
            " `Patient_city` TEXT," +
            "`Patient_contact` TEXT," +
            " `User_Id` INTEGER" +
            ");";

    String treatementMasterTable = "CREATE TABLE `treatement_master` (" +
            " `Treat_date` NUMERIC, " +
            " `Follow_Date` NUMERIC, " +
            " `Patient_complain` TEXT, " +
            " `Remarks` TEXT, " +
            " `Patient_image` TEXT, " +
            " `Status` TEXT, " +
            " `Patient_BP` INTEGER, " +
            " `SPO_two` INTEGER," +
            " `Patient_temp` REAL," +
            " `Referred_Doctor_Name` TEXT," +
            "`Referred_Hospital_Detail` TEXT, " +
            " `Advice` TEXT, " +
            " `Patient_pulse` INTEGER, " +
            " `Medicine` TEXT, " +
            " `Patient_Report_Detail` TEXT, " +
            " `Treat_crno` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," +
            " `Counsultancyfee` REAL, " +
           " `Is_Paid` BLOB, " +
            " `User_Id` INTEGER NOT NULL UNIQUE, " +
            " `Patient_Id` INTEGER NOT NULL UNIQUE, " +
            " FOREIGN KEY(`Patient_Id`) REFERENCES patient_master " +
            ");";

    db.execSQL(treatementMasterTable);

    Log.i("treatement table", "success");
    db.execSQL(patientMasterTable);
    Log.i("patient table", "success");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_PATIENT);
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_TREATEMENT);
    onCreate(db);       // Calling OnCreate method with database object.

}

1 个答案:

答案 0 :(得分:0)

如果您正在使用模拟器,您可以拉取db文件并检查表是否已创建,如果您使用的是设备,则可以使用此命令

cd / D D:\ Android \ SDK \ platform-tools

adb -d shell

run-as com.pkg.pkgname

cat /data/data/com.pkg.pkgname/databases/UR_DB_NAME> / sdcard / UR_DB_NAME

它会将您的db文件复制到设备SD卡。使用Sqlite browser,您可以打开db文件并检查表是否已创建

还尝试删除表名和字段名称周围的单个逗号,然后尝试。