Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么';MySQLiteHelper(扩展SQLiteOpenHelper)中的onCreate()是否执行?_Java_Android_Sqlite - Fatal编程技术网

Java 为什么';MySQLiteHelper(扩展SQLiteOpenHelper)中的onCreate()是否执行?

Java 为什么';MySQLiteHelper(扩展SQLiteOpenHelper)中的onCreate()是否执行?,java,android,sqlite,Java,Android,Sqlite,我有带sq-lite的代码,但有一些错误。我已经工作了几天,但它不工作。 我编写MySQLiteHelper类(扩展SQLiteOpenHelper) 我编写了MySQLiteDatabase类 public class MySQLiteDatabase { private static MySQLiteDatabase instance; private SQLiteDatabase sqLiteDatabase; private MySQLiteDatabase(C

我有带sq-lite的代码,但有一些错误。我已经工作了几天,但它不工作。 我编写MySQLiteHelper类(扩展SQLiteOpenHelper)

我编写了MySQLiteDatabase类

public class MySQLiteDatabase  {
    private static MySQLiteDatabase instance;
    private SQLiteDatabase sqLiteDatabase;
    private MySQLiteDatabase(Context context){
        MySQLiteHelper helper = new MySQLiteHelper(context,"test.db",null,1);
        sqLiteDatabase = helper.getWritableDatabase();
        sqLiteDatabase.execSQL("INSERT INTO classification(classification_id,classify) VALUES(1,'QQ')");
    }
    public static MySQLiteDatabase getInstance(Context context){
        if(null == instance){
            instance = new MySQLiteDatabase(context);
        }
        return instance;
    }
}
但是我在SampleActivity中的onCreate()中编写代码

MySQLiteDatabase my = MySQLiteDatabase.getInstance(SampleActivity.this);
MySQLiteHelper中的onCreate()不执行? 另一方面,我在示例活动的onCreate()中编写以下代码

 MySQLiteHelper helper = new MySQLiteHelper(context,"test.db",null,1);

我已经尽了最大的努力来解决它,但是我不能。请帮助我。

数据库帮助程序
onCreate()
仅在

  • 您正在调用
    getWritableDatabase()
    getReadableDatabase()
    ,并且

  • 数据库文件不存在


数据库文件可能已经存在。Uninstall您的应用程序或清除其数据以清除它。

您遇到了什么问题?因为它只被调用一次(如果数据库不存在)…如果此后您更改了表,则需要增加版本计数。并使用
getWritableDatabase()
。错误为NullPointerException堆栈跟踪包含的信息比此更多。如果你保守秘密,没有人能帮你。我认为我的代码符合要求,但它不起作用。我已经在MySQLiteDatabase'getIstance()中编写了getWritableDatabase(),为什么onCreate()不执行?
 MySQLiteHelper helper = new MySQLiteHelper(context,"test.db",null,1);