这是我的原木猫
java.lang.RuntimeException: Unable to start activity ComponentInfo{XXXXXX}: java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4482)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:442)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at com.gallops.CheckProfile.fillData(CheckProfile.java:171)
at com.gallops.CheckProfile.onCreate(CheckProfile.java:154)
at android.app.Activity.performCreate(Activity.java:4728)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
... 11 more
我正在尝试运行的查询://DBAdapter 文件
public Cursor fetchRow(String a) {
String Key = a;
return mDb.query(DATABASE_TABLE0, new String[] {IDno1, GIDno1,Name1,Owner1,Breed1,Gender1, Notes1,Nature1,Color1,Sire1,Dam1,Height1,Foaled1,Acquired1,Date1,IMG}, "IDno=?",new String[]{Key}, null, null, null, null);
}
我调用它的函数:
private void fillData() {
String D = getid();
Cursor c = DBHelper.fetchRow(IDB);
// List<String> idList = new ArrayList<String>();
if (c.moveToFirst()) {
do {
String X = (c.getString(c.getColumnIndexOrThrow("IDno")));
TextView tv2=(TextView)findViewById(R.id.textView3);
tv2.setText(X);
String B = (c.getString(c.getColumnIndexOrThrow("GIDno")));
TextView tv6=(TextView)findViewById(R.id.textView7);
tv6.setText(B);
String A = (c.getString(c.getColumnIndexOrThrow("Name")));
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setText(A);
NameTop = A;
String Y = (c.getString(c.getColumnIndexOrThrow("Owner")));
TextView tv12=(TextView)findViewById(R.id.textView13);
tv12.setText(Y);
String G = (c.getString(c.getColumnIndexOrThrow("Breed")));
TextView tv10=(TextView)findViewById(R.id.textView11);
tv10.setText(G);
String N = (c.getString(c.getColumnIndexOrThrow("Notes")));
TextView tv8=(TextView)findViewById(R.id.textView9);
tv8.setText(N);
String da = (c.getString(c.getColumnIndexOrThrow("Dam")));
TextView tv14=(TextView)findViewById(R.id.TextView02);
tv14.setText(da);
String si = (c.getString(c.getColumnIndexOrThrow("Sire")));
TextView tv16=(TextView)findViewById(R.id.TextView04);
tv16.setText(si);
String co = (c.getString(c.getColumnIndexOrThrow("Color")));
TextView tv18=(TextView)findViewById(R.id.TextView06);
tv18.setText(co);
String g = (c.getString(c.getColumnIndexOrThrow("Gender")));
TextView tv20=(TextView)findViewById(R.id.TextView08);
tv20.setText(g);
String na = (c.getString(c.getColumnIndexOrThrow("Nature")));
TextView tv22=(TextView)findViewById(R.id.TextView10);
tv22.setText(na);
String he = (c.getString(c.getColumnIndexOrThrow("Height")));
TextView tv24=(TextView)findViewById(R.id.TextView12);
tv24.setText(he);
String fo = (c.getString(c.getColumnIndexOrThrow("Foaled")));
//TextView tv26=(TextView)findViewById(R.id.TextView14);
//tv26.setText(fo);
String ac = (c.getString(c.getColumnIndexOrThrow("Acquired")));
TextView tv28=(TextView)findViewById(R.id.TextView16);
tv28.setText(ac);
/*Dt = (c.getString(c.getColumnIndexOrThrow("Date")));
int age = age(Dt);
TextView Tvx =(TextView)findViewById(R.id.textView5);
String DD = Integer.toString(age);
Tvx.setText(DD); */
Image = c.getBlob(c.getColumnIndex("image"));
if (Image!=null){
BitmapFactory.Options options = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeByteArray(Image, 0, Image.length, options);
ImageView Img = (ImageView)findViewById(R.id.imageView1);
Img.setImageBitmap(bitmap);
}else{
ImageView Img = (ImageView)findViewById(R.id.imageView1);
Img.setBackgroundResource(R.drawable.pic);
}
} while (c.moveToNext());
DBHelper.close();
}
}