我有一个数据库,里面有 2 个表。在 1 个表中,我有 id group 2 列。现在我想要的是我必须检索表中的组数据。
我的取货地点:
db.open();
for(int i=1;i<=5;i++)
{
if(i==1)
group1=db.getspintitle(1);
if(i==2)
group2=db.getspintitle(2);
if(i==3)
group3=db.getspintitle(3);
if(i==4)
group4=db.getspintitle(4);
if(i==5)
group5=db.getspintitle(5);
}
我的数据库代码:
public String getspintitle(int rowId)throws SQLException
{
String sumtotal="";
Cursor cursor1 = db.rawQuery(
"SELECT spin from spinner WHERE _id=rowId", null);
// sumtotal=cursor1.toString();
// cursor1.close();
for(int i=rowId;i<cursor1.getCount();i++)
{
if (cursor1 != null && cursor1.getCount() > 0)
{ cursor1.moveToNext();
sumtotal= cursor1.getString(i);
cursor1.close();
}
}
return sumtotal;
// String spin="SELECT spin from spinner WHERE _id='rowId' ";
// return spin;
}
我的日志是:
07-18 14:12:01.890: E/CursorWindow(27405): Bad request for field slot 0,1. numRows = 6, numColumns = 1
07-18 14:12:01.898: D/AndroidRuntime(27405): Shutting down VM
07-18 14:12:01.898: W/dalvikvm(27405): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-18 14:12:01.962: E/AndroidRuntime(27405): Uncaught handler: thread main exiting due to uncaught exception
07-18 14:12:02.000: E/AndroidRuntime(27405): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.budget1/com.budget1.Report}: java.lang.IllegalStateException: get field slot from row 0 col 1 failed
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.os.Looper.loop(Looper.java:123)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-18 14:12:02.000: E/AndroidRuntime(27405): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 14:12:02.000: E/AndroidRuntime(27405): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 14:12:02.000: E/AndroidRuntime(27405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-18 14:12:02.000: E/AndroidRuntime(27405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-18 14:12:02.000: E/AndroidRuntime(27405): at dalvik.system.NativeStart.main(Native Method)
07-18 14:12:02.000: E/AndroidRuntime(27405): Caused by: java.lang.IllegalStateException: get field slot from row 0 col 1 failed
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.database.CursorWindow.getString_native(Native Method)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.database.CursorWindow.getString(CursorWindow.java:329)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
07-18 14:12:02.000: E/AndroidRuntime(27405): at com.budget1.DBadapter.getspintitle(DBadapter.java:208)
07-18 14:12:02.000: E/AndroidRuntime(27405): at com.budget1.Report.onCreate(Report.java:65)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 14:12:02.000: E/AndroidRuntime(27405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-18 14:12:02.000: E/AndroidRuntime(27405): ... 11 more
07-18 14:12:02.078: I/dalvikvm(27405): threadid=7: reacting to signal 3
07-18 14:12:02.198: I/dalvikvm(27405): Wrote stack trace to '/data/anr/traces.txt'
07-18 14:17:02.150: I/Process(27405): Sending signal. PID: 27405 SIG: 9
07-18 14:17:04.198: I/System.out(6293): subbu
我哪里错了?