Android的数据库错误? [英] Android Database error?

查看:120
本文介绍了Android的数据库错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个菜单项在我的Andr​​oid应用程序,删除数据库中的所有的值,它为我调试目的使用较多,一段时间后,插入空值获得多余的。不管怎么说,我已经使用LogCat中,因为它在模拟器中运行调试我的程序,它给我一个错误:

I have a MenuItem in my Android application that deletes all the values in the database, its used more for my debugging purposes, after a while, inserting dummy values get redundant. Anyways, I have used LogCat to debug my program as it runs in the emulator and it gives me an error:

Failure 21 (out of memory) on 0x0 when preparing 'DELETE FROM <MY DBTABLE>'

我可以张贴code,但我怀疑它的code。

I can post the code but I doubt its the code.

public void deleteAll(SQLiteDatabase db) {
   try {
        db.execSQL("DELETE FROM " + DATABASE_TABLE);} 
        Log.v(TAG, "Deleting database");
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        Log.v(TAG, "Dropping table");
        onCreate(db);
        Log.v(TAG, "Creating new database");} 
   catch (NullPointerException e) { }
   catch (SQLException e) {}
   }
 }

    @Override
public void onCreate(SQLiteDatabase db) {
 // TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "LATITUDE INTEGER NOT NULL, LONGITUDE INTEGER NOT NULL, RATING INTEGER NOT NULL)");
}

这心不是我的现有功能,本来我方才:

This isnt my existing function, I had originally had just the:

db.execSQL("DELETE FROM " + DATABASE_TABLE);

但它没有工作,所以我评论它,然后想尽第一时间删除表和然后创建新表,但同样的错误。

but it didn't work, so I commented it out and then tried dropping the table first and THEN create a new table, but same error every time.

有谁知道为什么出现了这种错误,或者这个错误的方式不?

Does anyone know why this error occurred or a way for this error not to?

编辑:此方法不循环内运行,它的菜单按钮的一部分,当你选择它,调用deleteAll()方法。一个一点要注意,我通过我做了,就在这里澄清一个适配器类调用此方法是我的code的步进式:

This method does not run inside of a loop, its part of a Menu button, that when you select it, invokes the deleteAll() method. A point to note that I call this method through an Adapter class I had made, just to clarify here is the step-through of my code:

private TrackerDBAdapter db;

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case VIEW_DATABASE:
        Log.v(TAG, "Clicking on the view database menu option");
        Toast.makeText(this, "This should show the databases.",
                Toast.LENGTH_LONG).show();
        return true;
    case DELETE_VALUES:
        Log.v(TAG, "Clicking on the delete values menu option");
        db.deleteAll();
        Toast.makeText(this, "Database is empty",
                Toast.LENGTH_LONG).show();
        return true;

    }

然后我TrackAdapter类中。变量dbhelper是DatabaseHelper对象,它的第一个deleteAll(SQLiteDatabase DB)的问题code。

Then inside my TrackAdapter class. The variable dbhelper is a DatabaseHelper object, which has the first deleteAll(SQLiteDatabase db) code in the question.

private DatabaseHelper dbhelper;
private SQLiteDatabase db;

public void deleteAll() {
        dbhelper.deleteAll(db);
}

我不记得为什么我调用一个方法,调用另一个方法。这是出于绝望也许?但不管怎么说,我要反复折腾一下,看看是否我收拾code,也许这样做我可以回答我的问题。

I do not remember why I call a method, to call another method. It was out of desperation perhaps? But anyways, I am going to fiddle around with it and see if I clean up the code, maybe by doing so I can answer my own question.

推荐答案

而不是用DELETE FROM怎么样想一个DROP TABLE?从表A删除将创建事务日志空间。而一个DROP TABLE命令不会创建事务日志空间。这可能是你错误的原因。

instead of using Delete From how about trying a DROP TABLE? A delete from Table will create transaction log space. whereas a DROP TABLE command will not create Transaction log space. This could be the cause of your error.

这篇关于Android的数据库错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆