使用SQLite修复未找到数据路径错误 [英] Fixing data path not found error with SQLite
问题描述
我已经在编辑器中正常运行了sqlite db.但是,在Android中使用它时,出现错误消息,提示未找到数据路径.
I've got the sqlite db working in the editor just fine. However when using it in Android, I get an error saying data path not found.
我相信我在正确的plugins/android文件夹中具有所需的libsqlite.so文件,以及编辑器查找的其他DLL.
I believe I have the needed libsqlite.so files in the correct plugins/ android folder and the other DLLs that the editor looks for.
这是我的代码:
string filepath = Application.dataPath + "/" + "Players.db"; //.db
if(!File.Exists(filepath))
{
// if it doesn't ->
// open StreamingAssets directory and load the db ->
try {
WWW loadDB = new WWW ("jar:file://" + Application.persistentDataPath + "!/Assets/" + "StreamingAssets/Players.db"); // .db this is the path to your StreamingAssets in android
while (!loadDB.isDone) {
} // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
// then save to Application.persistentDataPath
File.WriteAllBytes (filepath, loadDB.bytes);
} catch (Exception ex) {
GameObject.Find ("Advice").GetComponent<Text> ().text = ex.Message;
}
}
推荐答案
您正在使用Application.DataPath
保存文件.在编辑器模式下,它指的是Assets文件夹,但在android build中,它指的是APK包,它是一个压缩文件,您无权访问.因此,请改用Application.persistentDataPath
.
You are using Application.DataPath
to save files. In editor mode it refers to Assets folder but in android build it refers to APK package which is a compressed file and you have no access to it. So use Application.persistentDataPath
instead.
string filepath = Application.persistentDataPath + "/" + "Players.db"; //.db
这篇关于使用SQLite修复未找到数据路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!