- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
请帮我解决错误:
D/AndroidRuntime(836): Shutting down VM
W/dalvikvm(836): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(836): FATAL EXCEPTION: main
E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.FirstProject/com.example.FirstProject.List}: java.lang.IllegalStateException: getWritableDatabase called recursively
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(836): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(836): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(836): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(836): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(836): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(836): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(836): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(836): Caused by: java.lang.IllegalStateException: getWritableDatabase called recursively
E/AndroidRuntime(836): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:81)
E/AndroidRuntime(836): at com.example.FirstProject.Database.onCreate(Database.java:36)
E/AndroidRuntime(836): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
E/AndroidRuntime(836): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
E/AndroidRuntime(836): at com.example.FirstProject.List.onCreate(List.java:38)
E/AndroidRuntime(836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(836): ... 11 more
代码:
package com.example.FirstProject;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class List extends ListActivity{
ListView stations;
protected int tn;
protected TextView source;
protected EditText searchText;
protected ListAdapter adapter;
protected Cursor cursor;
@Override
public void onCreate(Bundle savedInstanceState)throws IllegalStateException {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
tn = getIntent().getIntExtra("tn", 0);
SQLiteDatabase db = (new Database(this)).getReadableDatabase();
// searchText = (EditText) findViewById (android.R.id.list);
stations = (ListView) findViewById (android.R.id.list);
Cursor cursor = db.rawQuery("SELECT source._id,FROM tinfo WHERE city._id = Mumbai", new String[]{});
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.screen2, cursor, new String[] {}, new int[] {});
stations.setAdapter(adapter);
}
}
最佳答案
您可能在 onCreate()
或 onUpgrade( )
您的 SQLiteOpenHelper
实现。 getWritableDatabase()
调用 onCreate
(或 onUpgrade
),所以如果您在其中一个中调用了 getWritableDatabase()
你会遇到麻烦的方法。
这些方法有一个参数(SQLiteDatabase
对象),您必须使用它来执行数据库逻辑(因此您不能调用 getWritableDatabase()
(或 getReadableDatabase()
在里面)。
关于android - java.lang.IllegalStateException :getWritableDatabase called recursively 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9547259/
虽然我在理解递归方面没有任何问题,但我似乎无法理解汉诺塔问题的递归解决方案。这是来自 Wikipedia 的代码: procedure Hanoi(n: integer; source, dest,
虽然我在理解递归方面没有任何问题,但我似乎无法理解汉诺塔问题的递归解决方案。这是来自 Wikipedia 的代码: procedure Hanoi(n: integer; source, dest,
The Third Commandment的 The Little Schemer状态: When building a list, describe the first typical elemen
编辑 有关映射递归的“正确”Groovy 式方法,请参阅下面的@tim 解决方案。由于 Map findRecursive 在 Groovy 中尚不存在,如果您发现自己在应用程序的各个部分都需要此功能
这是尝试求解 3*3 的线性方程并打印结果,但在注释行中遇到了问题: 我在程序外部定义了 LinearSolution 模块,我应该在程序内部定义它吗?有什么区别? 为什么说该语句是递归的,你知道,当
我正在学习 Clojure 并从复制 Python 程序的功能开始,该程序将通过遵循(非常简单的)隐马尔可夫模型来创建基因组序列。 一开始,我坚持使用我已知的串行编程方式并大量使用 def 关键字,从
我有一个记录: type node = { content : string; parent : node option;
我发现 Java 8 已经显着清理了将文件内容读取到字符串中的过程: String contents = new String(Files.readAllBytes(Paths.get(new URI
我目前正在用 Java 编写一个图形库,我想要一个工具来可视化一些图形。我发现了 Graph-viz,它恰好是一种很好的(尽管有缺陷)做到这一点的方法。 在我的模型中,图由节点和边组成。每个节点都有一
昨天我遇到了这个pipes Common Lisp 库。它在某种程度上看起来很像 clojure 的惰性序列抽象,因此我决定使用它来实现 Common Lisp 中递归惰性斐波那契序列定义的经典(且优
昨天我遇到了这个pipes Common Lisp 库。它在某种程度上看起来很像 clojure 的惰性序列抽象,因此我决定使用它来实现 Common Lisp 中递归惰性斐波那契序列定义的经典(且优
我在开发一个递归函数时遇到了问题,该函数将查看两个列表是否彼此相等,包括查看子列表。到目前为止,我有: (defun are-equal2 (X Y) (cond ((null X) nil)
在 Abelson/Sussman 的经典著作《计算机程序的结构和解释》中,在关于树递归和斐波那契数列的第 1.2.2 节中,他们展示了这张图片: 计算第 5 个斐波那契数时生成的树递归过程 然后他们
SICP中的Section 1.2.1 中的作者在下面给出了这样的代码示例,以显示如何使用迭代过程解决阶乘问题: (define (factorial n) (fact-iter 1 1 n))
我继承了 的遗产Fortran 77 我现在的代码 试试 前往 编译 Fortran 2003 标准。我对 Fortran (我知道 C 和 Python)一无所知,我正在学习它。 下面的代码片段会导
这个警告来自哪里: Warning: `recursive` is deprecated, please use `recurse` instead 我在这里看到过:https://r-pkgs.or
Section 2.2 of the Happy user manual建议您使用左递归而不是右递归,因为右递归是“低效的”。基本上他们是说,如果您尝试解析一长串项目,右递归将溢出解析堆栈,而左递归使
问题 我有一个递归 CTE 查询,但是在创建循环时它失败了。我已经修复了简单的循环(例如 1 -> 2 -> 1),但无法修复更复杂的循环(例如 1 -> 2 -> 3 -> 2)。 查询详情 测试表
看完麻省理工学院的动态规划讲座后,我想练习一下斐波那契数列。我首先编写了朴素的递归实现,然后添加了内存。这是内存版本: package main import ( "fmt" ) func f
按照以下步骤,Cloudformation 堆栈可以进入递归锁: 在不导入值的情况下设置 CF(并创建堆栈) 使用相同的 CF 模板创建 soms 输出值(并更新堆栈) 在同一 CF 模板(和更新堆栈
我是一名优秀的程序员,十分优秀!