samedi 19 décembre 2015

How to solve database error message in android

Recently, i want to create dictionary app. I fixed a lot of error in android studio and compressed a lot of android code. Android Studio did not show red outline but "has stopped" message box is showed. This part is my code.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dictionary_display);
    ListView listsview = (ListView) findViewById(R.id.List);

    dbHelper = new SqlLiteDbHelper(this);
    dataBase = dbHelper.getWritableDatabase();

    Cursor mCursor = dataBase.rawQuery("SELECT * FROM dictionary ORDER BY id DESC ", null);

    word.clear();
    if (mCursor.moveToFirst()) {
        do {
            word.add(mCursor.getString(mCursor.getColumnIndex("word")));
        } while (mCursor.moveToNext());
    }
    list_Adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, word);
    listsview.setAdapter(list_Adapter);
    mCursor.close();
    }

This is error message.

12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1436)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1375)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at com.beyondplusmyanmar.it.mystudent.DictionaryActivity.onCreate(DictionaryActivity.java:55)
12-19 23:40:22.401 22464-22464/com.beyondplusmyanmar.it.mystudent E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5372)

Aucun commentaire:

Enregistrer un commentaire