gpt4 book ai didi

android - API 2.2 中没有这样的表

转载 作者:行者123 更新时间:2023-11-29 00:18:56 32 4
gpt4 key购买 nike

我的应用程序在较高版本中一切顺利,但在较低版本(如 2.2)中,应用程序在从数据库中获取数据时崩溃并出现此错误

07-17 21:46:36.361: I/Database(520): sqlite returned: error code = 1, msg = no such table: Schedules
07-17 21:46:36.371: W/System.err(520): android.database.sqlite.SQLiteException: no such table: Schedules: , while compiling: SELECT DISTINCT * FROM Schedules
07-17 21:46:36.391: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
07-17 21:46:36.391: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
07-17 21:46:36.401: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
07-17 21:46:36.462: W/System.err(520): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
07-17 21:46:36.462: W/System.err(520): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
07-17 21:46:36.485: W/System.err(520): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
07-17 21:46:36.492: W/System.err(520): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
07-17 21:46:36.492: W/System.err(520): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
07-17 21:46:36.502: W/System.err(520): at com.example.indianconstitution.DBAdapter.getSchedules(DBAdapter.java:148)
07-17 21:46:36.502: W/System.err(520): at com.example.indianconstitution.SchedulesFragment.onCreate(SchedulesFragment.java:37)
07-17 21:46:36.502: W/System.err(520): at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-17 21:46:36.521: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-17 21:46:36.521: W/System.err(520): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-17 21:46:36.521: W/System.err(520): at android.os.Handler.handleCallback(Handler.java:587)
07-17 21:46:36.521: W/System.err(520): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 21:46:36.521: W/System.err(520): at android.os.Looper.loop(Looper.java:123)
07-17 21:46:36.521: W/System.err(520): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 21:46:36.521: W/System.err(520): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 21:46:36.552: W/System.err(520): at java.lang.reflect.Method.invoke(Method.java:521)
07-17 21:46:36.552: W/System.err(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 21:46:36.571: W/System.err(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 21:46:36.571: W/System.err(520): at dalvik.system.NativeStart.main(Native Method)
07-17 21:46:36.661: D/AndroidRuntime(520): Shutting down VM
07-17 21:46:36.661: W/dalvikvm(520): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-17 21:46:36.691: E/AndroidRuntime(520): FATAL EXCEPTION: main
07-17 21:46:36.691: E/AndroidRuntime(520): java.lang.NullPointerException
07-17 21:46:36.691: E/AndroidRuntime(520): at com.example.indianconstitution.SchedulesAdapter.<init>(SchedulesAdapter.java:22)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.example.indianconstitution.SchedulesFragment.onCreateView(SchedulesFragment.java:58)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Handler.handleCallback(Handler.java:587)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Looper.loop(Looper.java:123)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 21:46:36.691: E/AndroidRuntime(520): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 21:46:36.691: E/AndroidRuntime(520): at java.lang.reflect.Method.invoke(Method.java:521)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 21:46:36.691: E/AndroidRuntime(520): at dalvik.system.NativeStart.main(Native Method)
07-17 21:46:36.892: D/dalvikvm(520): GC_FOR_MALLOC freed 3629 objects / 277352 bytes in 181ms

此链接http://www.anddev.org/networking-database-problems-f29/missing-table-in-sqlite-with-specific-version-of-desire-hd-t50364.html表明 htc desire 等手机存在一些问题,但我在 spice mi-270(2.2) 和模拟器 2.1、2.2 中也遇到了这个问题!

我正在使用这段代码作为我的 DBAdapter 类

public class DBAdapter extends SQLiteOpenHelper
{
//CustomAdapter adapter;
static String name = "law6.sqlite";
static String path = "";
static ArrayList<GS> gs;
static SQLiteDatabase sdb;

@Override
public void onCreate(SQLiteDatabase db)
{
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// TODO Auto-generated method stub
}

private DBAdapter(Context v)
{
super(v, name, null, 1);
path = "/data/data/" + v.getApplicationContext().getPackageName() + "/databases";
}

public boolean checkDatabase()
{
SQLiteDatabase db = null;
try
{
db = SQLiteDatabase.openDatabase(path + "/" + name, null, SQLiteDatabase.OPEN_READONLY);
} catch (Exception e)
{
e.printStackTrace();
}
if (db == null)
{
return false;
}
else
{
db.close();
return true;
}
}

public static synchronized DBAdapter getDBAdapter(Context v)
{
return (new DBAdapter(v));
}

public void createDatabase(Context v) throws IOException
{
this.getReadableDatabase();
try
{
InputStream myInput = v.getAssets().open(name);
// Path to the just created empty db
String outFileName = path +"/"+ name;
// Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0)
{
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();

} catch (IOException e)
{
System.out.println(e);
}
}

public void openDatabase()
{
try
{
sdb = SQLiteDatabase.openDatabase(path + "/" + name, null,
SQLiteDatabase.OPEN_READWRITE);
} catch (Exception e)
{
System.out.println(e);
}
}

public ArrayList<GS> getSchedules()
{
try{
Cursor c1 = sdb.query(true,"Schedules",null,null,null,null,null,null,null);//rawQuery("SELECT DISTINCT * FROM Schedules", null);
gs = new ArrayList<GS>();
while (c1.moveToNext())
{
GS q1 = new GS();
q1.setS_name(c1.getString(1));
q1.setP_name(c1.getString(2));
q1.setDesc(c1.getString(3));
gs.add(q1);
}
}
catch (Exception e) {
e.printStackTrace();
}
return gs;
}
}

我试过使用 query() 而不是 rawQuery() 但没有帮助!

我认为问题可能出在与 getReadableDatabase() 相关的 createDatabase()openDatabase() 中,或者我不知道是什么?

我正在使用这个获取这些数据

     DBAdapter db = DBAdapter.getDBAdapter(getActivity());

if (!db.checkDatabase())
try {
db.createDatabase(getActivity());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

db.openDatabase();

s = db.getSchedules();

任何想法...?

提前致谢

更新 这是我在 Jelly bean 中发现的日志记录,它显示异常但工作正常

07-25 10:24:35.721: E/Trace(14495): error opening trace file: No such file or directory (2)
07-25 10:24:37.351: I/Adreno200-EGL(14495): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: Nondeterministic AU_msm8625_REFS/TAGS/JB_REL_RB5_QRD_D20130221_CL3357771_release_AU (CL3357771)
07-25 10:24:37.351: I/Adreno200-EGL(14495): Build Date: 02/22/13 Fri
07-25 10:24:37.351: I/Adreno200-EGL(14495): Local Branch:
07-25 10:24:37.351: I/Adreno200-EGL(14495): Remote Branch: m/refs/tags/jb_rel_rb5_qrd_D20130221
07-25 10:24:37.351: I/Adreno200-EGL(14495): Local Patches: NONE
07-25 10:24:37.351: I/Adreno200-EGL(14495): Reconstruct Branch: NOTHING
07-25 10:24:38.031: I/Choreographer(14495): Skipped 50 frames! The application may be doing too much work on its main thread.
07-25 10:24:45.961: E/SQLiteLog(14495): (14) cannot open file at line 30178 of [00bb9c9ce4]
07-25 10:24:45.961: E/SQLiteLog(14495): (14) os_unix.c:30178: (2) open(/data/data/com.example.indianconstitution/databases/law6.sqlite) -
07-25 10:24:45.981: E/SQLiteDatabase(14495): Failed to open database '/data/data/com.example.indianconstitution/databases/law6.sqlite'.
07-25 10:24:45.981: E/SQLiteDatabase(14495): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at com.vivekwarde.indianconstitution.DBAdapter.checkDatabase(DBAdapter.java:44)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at com.vivekwarde.indianconstitution.ContentsFragment.onCreate(ContentsFragment.java:35)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.os.Handler.handleCallback(Handler.java:615)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.os.Looper.loop(Looper.java:137)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at android.app.ActivityThread.main(ActivityThread.java:4794)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-25 10:24:45.981: E/SQLiteDatabase(14495): at dalvik.system.NativeStart.main(Native Method)
07-25 10:24:45.981: W/System.err(14495): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
07-25 10:24:45.991: W/System.err(14495): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
07-25 10:24:45.991: W/System.err(14495): at com.vivekwarde.indianconstitution.DBAdapter.checkDatabase(DBAdapter.java:44)
07-25 10:24:45.991: W/System.err(14495): at com.vivekwarde.indianconstitution.ContentsFragment.onCreate(ContentsFragment.java:35)
07-25 10:24:45.991: W/System.err(14495): at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-25 10:24:45.991: W/System.err(14495): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-25 10:24:45.991: W/System.err(14495): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-25 10:24:46.001: W/System.err(14495): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-25 10:24:46.001: W/System.err(14495): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-25 10:24:46.001: W/System.err(14495): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-25 10:24:46.001: W/System.err(14495): at android.os.Handler.handleCallback(Handler.java:615)
07-25 10:24:46.001: W/System.err(14495): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 10:24:46.001: W/System.err(14495): at android.os.Looper.loop(Looper.java:137)
07-25 10:24:46.001: W/System.err(14495): at android.app.ActivityThread.main(ActivityThread.java:4794)
07-25 10:24:46.001: W/System.err(14495): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 10:24:46.001: W/System.err(14495): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 10:24:46.001: W/System.err(14495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-25 10:24:46.001: W/System.err(14495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-25 10:24:46.001: W/System.err(14495): at dalvik.system.NativeStart.main(Native Method)
07-25 10:24:49.081: I/Choreographer(14495): Skipped 174 frames! The application may be doing too much work on its main thread.

最佳答案

我有一个类似的问题,但事实证明这个问题与数据库无关,而是与应用程序中的内存使用有关。可以理解的是,较旧的 2.3 设备上的内存也较少,并且根据用户运行设备的环境,您的应用可能会遇到内存限制。

如果我正确地阅读了评论,您正在从您的 Assets 文件夹中处理一个 bundle 的 sqlite 数据库,如果您无法重现该问题,则可能是因为您的用户没有足够的 RAM 可用于您的应用程序,甚至有足够的磁盘空间来复制您的数据库。

largeHeap 在你的 list 中只适用于 Android 3.0+ 我相信即使你有那个设置它也不会解决旧手机的问题。我知道传统观点认为 Android 应用程序最初有 40mb 的堆空间,但我的研究表明这是一个推荐的大小并且不能保证,我遇到过 pre-honeycomb 设备(特别是索尼)只有 20MB对他们可用。

简而言之,我怀疑这是内存问题,而不是数据库问题。尝试为 2.3 及更低版本的设备提出一个替代的更轻重量策略,看看问题是否仍然存在。

关于android - API 2.2 中没有这样的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24406326/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com