Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android LG手机可以';无法访问SqLite数据库_Android_Database_Sqlite_Sqliteopenhelper_Lg - Fatal编程技术网

Android LG手机可以';无法访问SqLite数据库

Android LG手机可以';无法访问SqLite数据库,android,database,sqlite,sqliteopenhelper,lg,Android,Database,Sqlite,Sqliteopenhelper,Lg,我们已经为Android平台开发了一个预加载SQLite数据库的应用程序。使用SQLiteOpenHelper,在应用程序的第一次执行中,我们从应用程序数据目录(/data/data/br.com.lwu/databases/appdatabase.sqlite)的“Assets”复制数据库。 这在大多数设备中都有效。但我们的LG手机存在以下问题: LG擎天柱一号 LG-P500 LG-P500h 显然,数据库复制正确。但应用程序无法访问数据库(如表)。 我们需要帮助 // Copy Dat

我们已经为Android平台开发了一个预加载SQLite数据库的应用程序。使用SQLiteOpenHelper,在应用程序的第一次执行中,我们从应用程序数据目录(/data/data/br.com.lwu/databases/appdatabase.sqlite)的“Assets”复制数据库。 这在大多数设备中都有效。但我们的LG手机存在以下问题:

  • LG擎天柱一号
  • LG-P500
  • LG-P500h
显然,数据库复制正确。但应用程序无法访问数据库(如表)。 我们需要帮助

// Copy Database:

    private static String DB_PATH = "/data/data/br.com.lwu/databases/";
    private static String DB_NAME = "appdatabase.sqlite";


private void copyDataBase() throws IOException{
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();

    }


public void openDataBase() throws SQLException{ 
        String myPath = DB_PATH + DB_NAME;

        if (myDataBase == null) {
            myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
        }

    }

 @Override
    public synchronized void close() {

        super.close();

        if (myDataBase != null)
            if (myDataBase.isOpen()) {
                myDataBase.close();
                myDataBase = null;

            }

    }    
尝试更改:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
为此:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
          SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
这样做不需要您拥有android虚拟机所需的强制表
android\u元数据
,以防数据库中缺少该表。

尝试更改:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
为此:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
          SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);

这样做不需要您拥有android虚拟机所需的强制表,以防数据库中缺少该表。

显示代码,复制后您如何访问数据库?与问题是否相关,您不应假设使用私有存储路径,但是从适当的API获取它。向我们展示代码,在复制后如何访问数据库?与问题是否相关,您不应该假设私有存储路径,而是从适当的API获取它。