私のプログラムは、オプション (ボリューム、バイブレーションなど) が既に設定 (挿入) されているかどうか、オプション テーブルをチェックすることになっています。基本的に、オプションが設定されていない場合、テーブルの最初の列は 0 です。最初の行が空の場合はデフォルトのオプションに切り替え、そうでない場合はオプション セットに切り替えます。オプション チェッカーを try catch で囲み、このエラーを受け取ります。
CursorIndexOutOfBoundsException: サイズ 0 のインデックス 0 が要求されました。
私はまだこのSQLに慣れていないので、自分のコードが自分のニーズに合っているかどうかわかりません。
これは、OnCreate() での私のオプション チェッカーです。
options = new DBFunctions(this);
try{
String row = "0".toString();
long l = Long.parseLong(row);
options.open();
String retId = options.getId(l);
int id = Integer.parseInt(retId);
options.close();
//codes for setting the options if/if no data in option table exists will be put here
}catch(Exception e){
String error = e.toString();
tv.setText(error);
}
これは、DBFunctions の getId() です。ジャバ:
public String getId(long l) {
String[] columns = new String[]{"id", "volume", "vibrate", "theme"};
Cursor c = db.query(table, columns, "id=" + l, null, null, null, null);
if(c !=null){
c.moveToFirst();
String id = c.getString(1);
return id;
}
return null;
}
`