RuntimeError while retriving data from sqlite database in android

前端 未结 4 1740
情深已故
情深已故 2021-01-27 01:31

I\'m trying to insert and retrieve data from database in eclipse using sqlite, but it shows a RuntimeError. I create a layout with three edit texts and one button t

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-27 02:01

    ctxx is never initialzed, and this probably the cause of the crash. Generally speaking, when you deal with Activity and Fragment subclass, you almost never need to keep a reference to the Context. Activity is a subclass of Context, and usually this is enough. In a Fragment you can retrieve the context of the Activity hosting the Fragment with getActivity()

    Chante

     DBHelper DB=new DBHelper(ctxx);
    

    with

    DBHelper DB=new DBHelper(MainActivity.this);
    

    As @DerGolem pointed out, you are using the type INTEGER for the column MOTHER_NAME. Probably you want to use TEXT, instead, and you will also need a the primary key "_id"

      db.execSQL("CREATE TABLE " + TABLE_NAME + " ("
                    + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + NAME + " TEXT,"
                    + FATHER_NAME + " TEXT,"
                    + MOTHER_NAME + " TEXT"
                    + ");");
    

提交回复
热议问题