无法创建Android SQLite数据库:PRAGMA错误

无法创建Android SQLite数据库:PRAGMA错误,第1张

概述错误: E/Database( 8614): Failure 21 (out of memory) on 0x0 when preparing 'PRAGMA user_version = 1'.E/Database( 8614): Failure 21 (out of memory) on 0x0 when preparing 'ROLLBACK;'.D/Database( 8614): e 错误:

E/Database( 8614): Failure 21 (out of memory) on 0x0 when preparing 'PRAGMA user_version = 1'.E/Database( 8614): Failure 21 (out of memory) on 0x0 when preparing 'RolLBACK;'.D/Database( 8614): exception during rollback,maybe the DB prevIoUsly performed an auto-rollbackD/AndroIDRuntime( 8614): Shutting down VMW/dalvikvm( 8614): threadID=3: thread exiting with uncaught exception (group=0x4001dc20)E/AndroIDRuntime( 8614): Uncaught handler: thread main exiting due to uncaught exception

我目前的代码:

import androID.content.Context;import androID.database.Cursor;import androID.database.sqlite.sqliteDatabase;import androID.database.sqlite.sqliteOpenHelper;public class Database extends sqliteOpenHelper {   private static String Databasename = "EntrIEs.db";    public Database(Context context) {      super(context,Databasename,null,1);   }   public voID onCreate(sqliteDatabase D) {      D.execsql(            "CREATE table Containers ("            + "ID INTEGER PRIMARY KEY autoINCREMENT,"            + "Parent INTEGER,"            + "Sequence INTEGER,"            + "name TEXT"            + ")"      );      D.execsql(            "CREATE table files ("            + "ID INTEGER PRIMARY KEY autoINCREMENT,"            + "name TEXT,"            + "Text TEXT"            + ")"      );      D.execsql("INSERT INTO Containers (Parent,Sequence,name) VALUES (0,2,\"Testline2\")");      D.execsql("INSERT INTO Containers (Parent,1,\"Testline1\")");      D.execsql("INSERT INTO Containers (Parent,3,\"Testline3\")");      D.execsql("INSERT INTO Containers (Parent,name) VALUES (2,\"Testline2-1\")");      D.execsql("INSERT INTO Containers (Parent,\"Testline2-2\")");      D.close();   }   @OverrIDe   public voID onUpgrade(sqliteDatabase arg0,int arg1,int arg2) {   }   public static Cursor query(Context context,String sql) {      StartquerySerIEs(context);      Cursor Result = query(sql);      StopquerySerIEs();      return Result;   }   private static Database D = null;   public static voID StartquerySerIEs(Context context) {      D = new Database(context);   }   public static Cursor query(String sql) {      sqliteDatabase X = D.getWritableDatabase();      return X.rawquery(sql,null);   }   public static voID StopquerySerIEs() {      D.close();      D = null;   }}

当在主Activity中调用它时,会发生错误:

Database.query(this,"INSERT INTO files (Parent,name,Text) VALUES (1,\"Item1\",\"Item1 Text\")");

错误发生在“D.getWritableDatabase()”行…我最接近的事情是,在http://www.sqlite.org/c3ref/c_abort.html,故障21说“库使用不正确” – 任何帮助?

哦,我检查了 – 数据库文件确实已经创建了,但是里面没有表格,因此上面的onCreate()没有被调用.

解决方法 我在2分钟前遇到了同样的问题.我通过删除D.close()行来解决它.

当你关闭传递的sqliteDatabase对象时,似乎androID不喜欢它.我认为调用onCreate()方法的周围代码已经正确地管理打开和关闭数据库.所以你只需要做所有事情来获得表格.

也许在创建表之后,在这个对象上做了一些工作.我想知道这是否也解决了你的问题.

我也非常希望听到这种行为的确切解释.

总结

以上是内存溢出为你收集整理的无法创建Android SQLite数据库:PRAGMA错误全部内容,希望文章能够帮你解决无法创建Android SQLite数据库:PRAGMA错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1129543.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存