Androidアプリ開発初心者です
DBからデータを読んで自作アダプターを用いたListViewに表示しようとしていますが,実行時エラーで当該アクティビティに遷移した途端に落ちます.
コメントアウトする位置を変えたりして原因を探っていますが,いまいちよくわかりません.
以下LogCatです
lang
1E/AndroidRuntime(19527): 2 FATAL EXCEPTION: main 3 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.apphogehoge/com.example.apphogehoge.HogeActivity}: android.database.sqlite.SQLiteException: not an error (code 0) 4 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351) 5 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403) 6 at android.app.ActivityThread.access$600(ActivityThread.java:165) 7 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373) 8 at android.os.Handler.dispatchMessage(Handler.java:107) 9 at android.os.Looper.loop(Looper.java:194) 10 at android.app.ActivityThread.main(ActivityThread.java:5370) 11 at java.lang.reflect.Method.invokeNative(Native Method) 12 at java.lang.reflect.Method.invoke(Method.java:525) 13 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 14 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 15 at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:112) 16 at dalvik.system.NativeStart.main(Native Method) 17 Caused by: android.database.sqlite.SQLiteException: not an error (code 0) 18 at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) 19 at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:731) 20 at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) 21 at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) 22 at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1665) 23 at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) 24 at com.example.apphogehoge.DataBaseHelper.execSql(DataBaseHelper.java:73) 25 at com.example.apphogehoge.DataBaseHelper.onCreate(DataBaseHelper.java:35) 26 at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 27 at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 28 at com.example.apphogehoge.HogeActivity.onCreate(HogeActivity.java:32) 29 at android.app.Activity.performCreate(Activity.java:5122) 30 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146) 31 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315) 32 ... 12 more
このときのHogeActivityのonCreate
は次の通りです
lang
1 private DataBaseHelper helper = null; 2 private String hoge1 = "1001"; 3 private String hoge2 = "101"; 4 private String[] hoge4s; 5 private String[] hoge3s; 6 private String[] hoge5s; 7 8 @Override 9 protected void onCreate(Bundle savedInstanceState) { 10 super.onCreate(savedInstanceState); 11 setContentView(R.layout.hoge_activity); 12 13 helper = new DataBaseHelper(this); 14 15 SQLiteDatabase db = helper.getReadableDatabase(); 16 String[] cols = {"id", "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", "hoge6"}; 17 String[] params = {hoge1, hoge2}; 18 /* 19 Cursor cs = db.query("tablehoge", cols, "hoge1 = ? and hoge2 = ?", params, null, null, "id desc", null); 20 if (cs.moveToFirst()) { 21 int i = 0; 22 do { 23 hoge4s[i] = cs.getString(4); 24 hoge3s[i] = cs.getString(3); 25 hoge5s[i] = cs.getString(5); 26 i++; 27 }while(cs.moveToNext()); 28 } 29 30 // 配列の内容をListItemに詰め替え 31 ArrayList<HogeListItem> data = new ArrayList<HogeListItem>(); 32 for (int i = 0; i < hoge4s.length; i++){ 33 HogeListItem item = new HogeListItem(); 34 item.setId_usrmsg((new Random()).nextLong()); 35 item.setUsrmsg(hoge4s[i]); 36 item.setDate(hoge3s[i]); 37 item.setGoodnum(hoge5s[i]); 38 data.add(item); 39 } 40 41 // ListItem配列とレイアウトとを関連付け 42 ListAdapterUsrMsg adapter = new ListAdapterHoge(this, data, R.layout.hoge_listitem); 43 ListView list = (ListView)findViewById(R.id.lv_hoge); 44 list.setAdapter(adapter); 45 */
エラー文中のHogeActivity.java:32
はSQLiteDatabase db = helper.getReadableDatabase();
を指しています.
なにが問題なのでしょうか?
よろしくお願いいたします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/01 16:34
2015/03/01 16:40
2015/03/02 09:13