繰り返しの質問で申し訳ありませんが、私は多くの方法を試してみましたが、うまくいきません。しかし、その時は間違いでした。
SQLiteDatabase mDb;
Database3 mHelper;
SQLiteDatabase mDb2;
Database mHelper2;
private Cursor mCursor;
private String name;
private String image;
private String location;
private String info;
private String shop;
private String mcontact;
mHelper2 = new Database(this,shop);
mDb2 = mHelper2.getWritableDatabase();
mHelper2.onUpgrade(mDb2, 1, 1);
if (info.equalsIgnoreCase("null")){
AlertDialog.Builder builder = new AlertDialog.Builder(Activity_Mall_Floor.this);
builder.setTitle("Floor Description");
builder.setMessage("No Floor information of "+name);
builder.setNeutralButton("OK", null);
builder.show();
}
else {
ListView listView1 = (ListView)findViewById(R.id.listView2);
mHelper = new Database3(this,info);
mDb = mHelper.getWritableDatabase();
mHelper.onUpgrade(mDb, 1, 1);
mCursor = mDb.rawQuery("SELECT " + Database3.COL_FLOOR + ", "
+ Database3.COL_IMAGE+ " FROM " + Database3.TABLE_NAME, null);
ArrayList<String> dirArray = new ArrayList<String>();
mCursor.moveToFirst();
while ( !mCursor.isAfterLast() ){
dirArray.add(mCursor.getString
(mCursor.getColumnIndex(Database3.COL_FLOOR)));
mCursor.moveToNext();
}
ArrayAdapter<String> adapterDir =
new ArrayAdapter<String>(getApplicationContext()
, android.R.layout.simple_list_item_1, dirArray);
listView1.setAdapter(adapterDir);
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
mCursor.moveToPosition(arg2);
String floorName = mCursor.getString(mCursor.getColumnIndex(Database3.COL_FLOOR));
String mapFloor = mCursor.getString(mCursor.getColumnIndex(Database3.COL_IMAGE));
String floor = "";
if(floorName.equalsIgnoreCase("1st Floor"))
floor = "1";
else if (floorName.equalsIgnoreCase("2nd Floor"))
floor = "2";
else if (floorName.equalsIgnoreCase("3rd Floor"))
floor = "3";
else
floor = "4";
mCursor = mDb2.rawQuery("SELECT DISTINCT " + Database.COL_NAME
+" FROM " + Database.TABLE_NAME
+" WHERE " + Database.COL_FLOOR + " = '" + floor +"' ", null);
ArrayList<String> dirArray = new ArrayList<String>();
mCursor.moveToFirst();
while ( !mCursor.isAfterLast() ){
dirArray.add(mCursor.getString
(mCursor.getColumnIndex(Database.COL_NAME)));
mCursor.moveToNext();
}
Intent intent = new Intent(getApplicationContext(), Activity_Mall_FMap.class);
Bundle bundle = new Bundle();
bundle.putString("Floorname", floorName);
bundle.putString("Mapfloor", mapFloor);
bundle.putString("Shop", shop);
intent.putExtra("FloorList",dirArray);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
エラーフォーム logcat
02-12 01:31:46.917: E/AndroidRuntime(11370): FATAL EXCEPTION: main
02-12 01:31:46.917: E/AndroidRuntime(11370): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.database.CursorWindow.nativeGetString(Native Method)
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.database.CursorWindow.getString(CursorWindow.java:442)
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
02-12 01:31:46.917: E/AndroidRuntime(11370): at com.test.mall.Activity_Mall_Floor$1.onItemClick(Activity_Mall_Floor.java:85)
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.widget.AbsListView.performItemClick(AbsListView.java:1068)
02-12 01:31:46.917: E/AndroidRuntime(11370): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2525)
これはエラー行85です
String floorName = mCursor.getString(mCursor.getColumnIndex(Database3.COL_FLOOR));
String mapFloor = mCursor.getString(mCursor.getColumnIndex(Database3.COL_IMAGE));
ご案内ありがとうございます。