Android java.lang.IllegalStateException:递归调用getWritableDatabase

Android java.lang.IllegalStateException:递归调用getWritableDatabase,android,sqlite,android-listview,Android,Sqlite,Android Listview,请帮助我解决错误: 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 a

请帮助我解决错误:

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);

 }

}

需要查看代码,但我怀疑您在启动时没有在正确的位置调用SQLiteOpenHelper

可以在onCreate()中创建SQLiteOpenHelper对象,但在需要读写之前不要打开数据库。在内容提供者中,标准模式是创建 ContentProvider.onCreate()中的SQLiteOpenHelper,但在
进入访问。

您可能在
SQLiteOpenHelper
实现的
onCreate()
onUpgrade()
方法之一中调用
getWritableDatabase()
(或
getReadableDatabase()
getWritableDatabase()
调用
onCreate
(或
onUpgrade
),因此,如果在其中一个方法中调用了
getWritableDatabase()
,您将遇到麻烦


这些方法有一个参数(一个
SQLiteDatabase
对象),您必须使用它来执行数据库逻辑(因此您不能调用
getwriteabledatabase()
(或其中的
getReadableDatabase()
).

添加您的代码,我们可能会帮助您。嘿,朋友们,我已经添加了代码。请检查并告诉我如何解决该错误…请帮助。这仍然不够。我们需要您的
数据库
类的代码。请留下它。我已更改了显示数据的方式。