I have an application that works fine on Android 2.1, but when I try to transfer it to 3.0, I get an error with a cursor that I am not familiar with.
Java.lang.IllegalStateException: Failed to read row0, column -1 from cursor window. Make sure that the cursor is initialized correctly accessing data from it.
All data is stored in a SQLite database, and this code works fine in android 2.1. Does the cursor need to be initialized differently in Android 3.0?
Below is my code.
private void OpenGroupData(){ SQLiteDatabase db = openOrCreateDatabase(DATABASE_NAME,Context.MODE_PRIVATE,null); Cursor cur = db.rawQuery("SELECT groupid FROM properties GROUP BY GroupID" + ";" , null); LinearLayout glayout = (LinearLayout) findViewById(R.id.Grouplayout); LinearLayout gwindow = (LinearLayout) findViewById(R.id.groupwindow); TextView data = new TextView(this); glayout.addView(data); data.setText(""); int ID = cur.getColumnIndex("groupid"); int idvalue; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); try{ // Check if our result was valid. cur.moveToFirst(); if (cur != null) { // Loop through all Results do {data = new TextView(this); data.setTextSize(20); data.setClickable(true); data.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { GroupClick(v); } }); glayout.addView(data); idvalue = cur.getInt(ID); data.setId(idvalue); data.setText("Group: " + idvalue); }while(cur.moveToNext()); } cur.close(); db.close(); } catch(Exception e) { Toast.makeText(getApplicationContext(), "Open Group Exception: " + e.toString(), Toast.LENGTH_SHORT).show(); } }
source share