Android 不能';我找不到这样的桌子

Android 不能';我找不到这样的桌子,android,sqlite,Android,Sqlite,我正在创建一个应用程序,将其数据缓存在SQLite数据库中,但我不想以编程方式创建数据库。我使用SQLite浏览器创建了数据库,然后将其导入到我的资产文件夹中,但每次尝试对此数据库执行任何操作时,我都没有收到此类表异常 我知道关于这个问题有很多问题,但没有一个对我有帮助。 这是我的SQLiteOpenHelper public class MySQLiteHelper extends SQLiteOpenHelper { public SQLiteDatabase myDataBase; pri

我正在创建一个应用程序,将其数据缓存在SQLite数据库中,但我不想以编程方式创建数据库。我使用SQLite浏览器创建了数据库,然后将其导入到我的资产文件夹中,但每次尝试对此数据库执行任何操作时,我都没有收到此类表异常

我知道关于这个问题有很多问题,但没有一个对我有帮助。
这是我的
SQLiteOpenHelper

public class MySQLiteHelper extends SQLiteOpenHelper {
public SQLiteDatabase myDataBase;
private final Context myContext;
private static final String DATABASE_NAME = "VadDB";
public  static String DATABASE_PATH = "";
public static final int DATABASE_VERSION = 2;

// public static final int DATABASE_VERSION_old = 1;

// Constructor
public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    if(android.os.Build.VERSION.SDK_INT >= 17){
        DATABASE_PATH = context.getApplicationInfo().dataDir + "/databases/";
    }
    else
    {
        DATABASE_PATH = "/data/data/" + context.getPackageName() + "/databases/";
    }
    this.myContext = context;
}

// Create a empty database on the system
public void createDataBase() throws IOException {
    // boolean dbExist = checkDataBase();
    //
    // if (dbExist) {
    // Log.v("DB Exists", "db exists");
    // // By calling this method here onUpgrade will be called on a
    // // writeable database, but only if the version number has been
    // // bumped
    // // onUpgrade(myDataBase, DATABASE_VERSION_old, DATABASE_VERSION);
    // }

    boolean dbExist1 = checkDataBase();
    if (!dbExist1) {
        this.getReadableDatabase();
        try {
            this.close();
            copyDataBase();
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
    }
}

// Check database already exist or not
private boolean checkDataBase() {
    boolean checkDB = false;
    try {
        String myPath = DATABASE_PATH + DATABASE_NAME;
        File dbfile = new File(myPath);
        checkDB = dbfile.exists();
    } catch (SQLiteException e) {
    }
    return checkDB;
}

// Copies your database from your local assets-folder to the just created
// empty database in the system folder
private void copyDataBase() throws IOException {
    String outFileName = DATABASE_PATH + DATABASE_NAME;
    OutputStream myOutput = new FileOutputStream(outFileName);
    InputStream myInput = myContext.getAssets().open(DATABASE_NAME);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    myInput.close();
    myOutput.flush();
    myOutput.close();
}

// delete database
public void db_delete() {
    File file = new File(DATABASE_PATH + DATABASE_NAME);
    if (file.exists()) {
        file.delete();
    }
}

public Cursor query(String table, String[] columns, String selection,
                    String[] selectionArgs, String groupBy, String having,
                    String orderBy) {
    return myDataBase.query("data_table", null, null, null, null, null,
            null);

}

public Cursor queryDatabase(String sql) {
    Cursor cursor = myDataBase.rawQuery(sql, null);
    return cursor;
}

// Open database
public void openDataBase() throws SQLException {
    String myPath = DATABASE_PATH + DATABASE_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
}

public synchronized void closeDataBase() throws SQLException {
    if (myDataBase != null)
        myDataBase.close();
    super.close();
}

@Override
public void onCreate(SQLiteDatabase db) {
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (newVersion > oldVersion) {
        db_delete();
    }
}
这就是我使用它的方式

     MySQLiteHelper helper=new MySQLiteHelper(context);
    SQLiteDatabase db1 = helper.getWritableDatabase();
    System.out.println(db1.getPath());
    for(int i=0;i<faqlist.size();i++){
        ContentValues values = new ContentValues();
        values.put("ModuleId", faqlist.get(i).getModuleId());
        values.put("Title",faqlist.get(i).getTitle() );
        values.put("Category", faqlist.get(i).getCategory());
        values.put("CetegoryId", faqlist.get(i).getCategoryId());
        values.put("Question", faqlist.get(i).getQuestion());
        values.put("Answer", faqlist.get(i).getAnswer());
       db1.insert("Faq1", null, values);
    }
MySQLiteHelper=新的MySQLiteHelper(上下文);
SQLiteDatabase db1=helper.getWritableDatabase();
System.out.println(db1.getPath());

对于(int i=0;i在向资产添加新的
DB
后,你必须卸载你的应用程序并安装新的
.apk
重新构建。我已经尝试过很多次了你是否在Android Studio>??是的,我在使用Android Studio,我想这就是问题的原因。因为上周我在
中发现了与(beta-0.9.9)相同的问题
虽然与我在
AS(1.2.1)
中使用的
DB相同,但它工作得很好。但是当我重新启动
AS(0.9.9)
时,它工作得很好,一点问题也没有。所以我想
Android Studio
不会识别更新的
DB
是因为
是旧版本的