java.lang.IllegalStateException:getWritableDatabase递归调用 [英] java.lang.IllegalStateException:getWritableDatabase called recursively

查看:307
本文介绍了java.lang.IllegalStateException:getWritableDatabase递归调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我rsolve错误:

  D / AndroidRuntime(836):关闭VM
W / dalvikvm(836):主题ID = 1:螺纹未捕获的异常退出(组= 0x4001d800)
E / AndroidRuntime(836):致命异常:主要
E / AndroidRuntime(836):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.FirstProject / com.example.FirstProject.List}:java.lang.IllegalStateException:getWritableDatabase递归调用
E / AndroidRuntime(836):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E / AndroidRuntime(836):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E / AndroidRuntime(836):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
E / AndroidRuntime(836):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
E / AndroidRuntime(836):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(836):在android.os.Looper.loop(Looper.java:123)
E / AndroidRuntime(836):在android.app.ActivityThread.main(ActivityThread.java:4627)
E / AndroidRuntime(836):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(836):在java.lang.reflect.Method.invoke(Method.java:521)
E / AndroidRuntime(836):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
E / AndroidRuntime(836):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E / AndroidRuntime(836):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(836):java.lang.IllegalStateException:致getWritableDatabase递归调用
E / AndroidRuntime(836):在android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:81)
E / AndroidRuntime(836):在com.example.FirstProject.Database.onCreate(Database.java:36)
E / AndroidRuntime(836):在android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
E / AndroidRuntime(836):在android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
E / AndroidRuntime(836):在com.example.FirstProject.List.onCreate(List.java:38)
E / AndroidRuntime(836):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E / AndroidRuntime(836):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E / AndroidRuntime(836):11 ...更多

code:

 包com.example.FirstProject;进口android.app.Activity;
进口android.app.ListActivity;
进口android.content.Intent;
进口android.database.Cursor;
进口android.database.sqlite.SQLiteDatabase;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.ArrayAdapter;
进口android.widget.EditText;
进口android.widget.ListAdapter;
进口android.widget.ListView;
进口android.widget.SimpleCursorAdapter;
进口android.widget.TextView;
进口android.widget.Toast;公共类列表扩展ListActivity {
ListView控件站;
保护INT TN;
保护TextView的来源;
受保护的EditText SEARCHTEXT;
保护ListAdapter适配器;
保护光标指针;
 @覆盖
    公共无效的onCreate(捆绑savedInstanceState)抛出IllegalStateException异常{
        super.onCreate(savedInstanceState);        的setContentView(R.layout.screen2);       。TN = getIntent()getIntExtra(TN,0);
       SQLiteDatabase DB =(新的数据库(本))getReadableDatabase()。
      // SEARCHTEXT =(EditText上)findViewById(android.R.id.list);
        站=(ListView控件)findViewById(android.R.id.list);
        光标光标= db.rawQuery(SELECT source._id从TINFO WHERE city._id =孟买,新的String [] {});
        startManagingCursor(光标);        适配器=新SimpleCursorAdapter(这一点,R.layout.screen2,光标,新的String [] {},新的INT [] {});
        stations.setAdapter(适配器); }}


解决方案

您可能叫 getWritableDatabase()(或 getReadableDatabase()的onCreate() onUpgrade() SQLiteOpenHelper getWritableDatabase()通话的onCreate (或 onUpgrade ),所以如果你有这些,你会遇到麻烦运行方法之一 getWritableDatabase()电话。

这些方法有一个参数( SQLiteDatabase )对象,必须使用做你的数据库逻辑(所以你不能调用 getWritableDatabase() (或 getReadableDatabase()在那里)。

Please help me to rsolve the error :

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

code:

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

 }

}

解决方案

You probably call getWritableDatabase()(or getReadableDatabase()) in one of the methods onCreate() or onUpgrade() of your implementation of SQLiteOpenHelper. getWritableDatabase() calls onCreate(or onUpgrade) so if you have a getWritableDatabase() call in one of those methods you will run in trouble.

Those methods have a parameter (a SQLiteDatabase object) that you must use to do your database logic(so you must NOT call getWritableDatabase() (or getReadableDatabase() in there).

这篇关于java.lang.IllegalStateException:getWritableDatabase递归调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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