0

我最近在我的 android 应用程序中使用时遇到错误getReadableDatabase(),它返回 null。

DatabaseHelper的是这样的:

package com.example.borec;

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

public class DatabaseHelper extends SQLiteOpenHelper {

    private static final int VERSION = 1;

    public DatabaseHelper(Context context, String name, CursorFactory factory,
            int version) {
        super(context, name, factory, version);
    }

    public DatabaseHelper(Context context, String name) {
        this(context, name, VERSION);
    }

    public DatabaseHelper(Context context, String name, int version) {
        this(context, name, null, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        System.out.println("create a Database");
        db.execSQL("create table users(uid varchar(10),user_name varchar(30))");
        db.execSQL("create table status(create_at varchar(40),datelong integer,id varchar(10),text varchar(1000),user_name varchar(30),uid varchar(10),annotations varchar(1000))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        System.out.println("update a Database");
    }
}

我在一个活动中使用这个助手:

DatabaseHelper dbHelper = new DatabaseHelper(DataOperatorActivity.this, "borec");
db = dbHelper.getReadableDatabase();

第二条语句返回null?谁知道为什么?

4

0 回答 0