In my application, there is a few lines of code for retrieving data from multiple database.
Code:
String testquiry = "select a.rowid as _id, "
+ "a.delivery_seq sequence, "
+ "a.chinese_name chinese_name, "
+ "b.cust_code cust_code, "
+ "a.status status "
+ "from route_cust a, customer_file b, pda c "
+ "where a.cust_code = b.cust_code "
+ "and b.cust_status = 'A' "
+ "and b.route = c.route "
+ "and c.default_route = 'Y' "
+ "order by a.delivery_seq";
String testResult;
Cursor testCur = db.rawQuery(testquiry, null);
if(testCur.moveToFirst()){
testResult = testCur.getString(cur_getimportcsv.getColumnIndex("status"));
Toast.makeText(v.getContext(), testResult, Toast.LENGTH_LONG).show();
}
testCur.close();
When the application run to the following code, errors occur.
testResult = testCur.getString(cur_getimportcsv.getColumnIndex("status"));
Error displayed in LogCat:
09-03 15:53:36.533: W/dalvikvm(23398): threadid=1: thread exiting with uncaught exception (group=0x415abba8)
09-03 15:53:36.563: E/AndroidRuntime(23398): FATAL EXCEPTION: main
09-03 15:53:36.563: E/AndroidRuntime(23398): Process: com.iceapp, PID: 23398
09-03 15:53:36.563: E/AndroidRuntime(23398): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.database.CursorWindow.nativeGetString(Native Method)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.database.CursorWindow.getString(CursorWindow.java:434)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
09-03 15:53:36.563: E/AndroidRuntime(23398): at com.iceapp.ImportCsvActivity$2.onClick(ImportCsvActivity.java:285)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.view.View.performClick(View.java:4438)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.view.View$PerformClick.run(View.java:18422)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.os.Handler.handleCallback(Handler.java:733)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.os.Handler.dispatchMessage(Handler.java:95)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.os.Looper.loop(Looper.java:136)
09-03 15:53:36.563: E/AndroidRuntime(23398): at android.app.ActivityThread.main(ActivityThread.java:5001)
09-03 15:53:36.563: E/AndroidRuntime(23398): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 15:53:36.563: E/AndroidRuntime(23398): at java.lang.reflect.Method.invoke(Method.java:515)
09-03 15:53:36.563: E/AndroidRuntime(23398): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-03 15:53:36.563: E/AndroidRuntime(23398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-03 15:53:36.563: E/AndroidRuntime(23398): at dalvik.system.NativeStart.main(Native Method)
I have studied other similar question on stackoverflow, I found that this problem was caused by unsuccessful fetch of column "status". Can anyone give me some help? Why the value of 'status' cannot be got successfully??
testCurnot fromcur_getimportcsv