日期:2014-05-16  浏览次数:20400 次

android java.lang.IllegalStateException: database not open 错误
package com.taobao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "taobao";
	private static final int DATABASE_VERSION = 1;

	DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

//		String sql = "CREATE TABLE " + TABLE_NAME + " (" + TITLE
//				+ " text not null, " + BODY + " text not null " + ");";
		String sql="create table  brand (id text,url text,title text)";
		String sql2="create table  faver (id text,title text)";
		db.execSQL(sql);
		db.execSQL(sql2);
		//db.close();
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	}

}




出现  java.lang.IllegalStateException: database not open 错误  db.close(); 注释掉就可以 
1 楼 cl1_1_1 2012-08-04