gpt4 book ai didi

android - 设备崩溃

转载 作者:行者123 更新时间:2023-12-03 17:41:18 24 4
gpt4 key购买 nike

我有一个应用程序,我使用数据库在 ListView 中插入值。当我在合并后在模拟器上运行应用程序时,它运行良好,但在开始插入值时在设备上崩溃,LogCat 向我显示:关闭光标,但我已经关闭了所有开始打开的类(class)。
这是按钮 Action

plus.setOnClickListener(new View.OnClickListener() {


public void onClick(View v)
{

tx = txt.getText().toString();
postive.add(tx);
if(tx.length() >0)
{
myDB.execSQL("INSERT INTO UP (ID,UPNAME) VALUES ('"+idnum+"','"+tx+"')");

txt.setText("");
function();
results.clear();
Intent i=new Intent(Positive.this,NewgridActivity.class);
bundle.putInt("tabid", 1);
bundle.putInt("id", idnum);
i.putExtras(bundle);
startActivity(i);
finish();
}
else
DisplayToast("TextField Empty !!!!");

}
});

请提供任何帮助。

logcat 中的错误
12-21 13:11:02.582: E/Database(4909): close() was never explicitly called on database '/data/data/pa.gd/databases/DECISION_GRID' 
12-21 13:11:02.582: E/Database(4909): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
12-21 13:11:02.582: E/Database(4909): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
12-21 13:11:02.582: E/Database(4909): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
12-21 13:11:02.582: E/Database(4909): at pa.gd.PAIDGRIDActivity.onCreate(PAIDGRIDActivity.java:66)
12-21 13:11:02.582: E/Database(4909): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 13:11:02.582: E/Database(4909): at dalvik.system.NativeStart.main(Native Method)

关闭数据库后记录错误

当我尝试添加一个值时,我已经关闭了数据库,它会因此日志错误而崩溃
12-21 15:45:58.043: E/AndroidRuntime(401): FATAL EXCEPTION: main
12-21 15:45:58.043: E/AndroidRuntime(401): java.lang.IllegalStateException: database not open
12-21 15:45:58.043: E/AndroidRuntime(401): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1723)
12-21 15:45:58.043: E/AndroidRuntime(401): at dc.grd.Positive$1.onClick(Positive.java:77)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.view.View.performClick(View.java:2408)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.view.View$PerformClick.run(View.java:8816)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Handler.handleCallback(Handler.java:587)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Looper.loop(Looper.java:123)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:45:58.043: E/AndroidRuntime(401): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:45:58.043: E/AndroidRuntime(401): at java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:45:58.043: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 15:45:58.043: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-21 15:45:58.043: E/AndroidRuntime(401): at dalvik.system.NativeStart.main(Native Method)

最佳答案

考虑一下数据库连接的生命周期。我建议在您的应用程序类或 onResume() 中打开数据库。你的 Activity 方法。关闭onPause()中的数据库.

每当您使用数据库时,请确保在使用完数据库后正确关闭所有游标。

顺便说一句:每次你像以前那样写一个问题标题,一只小猫就会死去......

关于android - 设备崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8586148/

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