android - Getting object from DB returns empty object or app crashes -
In my DB Manager class, I have a way of recovering the selected group with group_db and trip_db parameters.
public selected_ group get_selected_group_by_group_id_and_trip_id (int trip_id, int group_id) {open_readable (); Cursor cursor = db.query (static.tablets_names.TABLE_NAME_SELECTED_GROUPS, blank, "trip_id =" + trip_id + "& group_id =" + group_id, empty, blank, empty, empty); Int sg_id = 0; Int sg_trip_id = 0; Int sg_group_id = 0; While (cursor.movteonxt ()) {sg_id = cursor.getInt (0); Sg_trip_id = Cursor.Gist (1); Sg_group_id = cursor.getInt (2); } Selected_groupsg = new selected_groups (sg_id, sg_trip_id, sg_group_id); Cursor.close (); Close (); Return sg; }However in this case the cursor skips the entire
while
loop and I am getting a selected group with initial values, i.e. _id = 0So I tried it like this:
gets the public chosen group - selected / group_by_graph_id_ and_trop_id (int trip_id, int group_id) {open_readable (); Cursor cursor = db.query (static.tablets_names.TABLE_NAME_SELECTED_GROUPS, blank, "trip_id =" + trip_id + "& group_id =" + group_id, empty, blank, empty, empty); Cursor.moveToFirst (); Int sg_id = cursor.getInt (0); Int sg_trip_id = cursor.getInt (1); Int sg_group_id = cursor.getInt (2); Selected_Group sg = New Selected_Group (sg_id, sg_trip_id, sg_group_id); Cursor.close (); Close (); Return sg; }
In this case, the app crashes with the following error message:
08-01 14: 31: 17.416: E / Andorrentime ( 13385): Fatal avisepion: Main 08-01 14: 31: 17.416: E / Android Random (13385): android.database.CursorIndexOutOfBoundsException: Index 0 0 08-01 14: 31: 17.416: Size of E / Andorrentime (13385) Requested with: At android.database.AbstractCursor.checkPosition (AbstractCursor.java:400) 08-01 14: 31: 17.416: E / Android Time (13385): On the Android Database. Abovewondowword Cursors. Checkpoint (Abbottwonded Cursors.Javier 36) 08-01 14: 31: 17.416: E / Android Rendime (13385): On Android Databases Abob Winder cursor.gate (Abbottwonded Cursor. Java: 68) 08-01-14: 31: 17.416: E / Androindertime (13385): at com.mycompany.myapp. Tasks. Task_DB_Manager.get_selected_group_by_group_id_and_trip_id (Task_DB_Manager.java ** 42) 08-01-14: 31: 17.416: E / Android Time (13385): 08.01 14 at com.mycompany.myapp.activities.Activity_Add_Edit_Trip.onClick (Activity_Add_Edit_Trip.java .63) : 31: 17.416: E / Android Random (13385): Android. View.View.performClick (see .Java 3511) 08-01 14: 31: 17.416: E / Android Time (13385): $ PerformClick.run at android.view.View (see .Java14105) 08-01 14: 31: 17.416 : E / AndroidDime (13385): Android.OSHandlerHandley Callback (HandlerJava: 605) 08-01 14: 31: 17.416: E / Android Random (Android): Android. OS Handler Dispatch Message (Handler. Java) 08-01 14: 31: 17.416: E / Android Rendime (13385): Android. Los. Looper Oops (Looper Java: 137) 08-01 14: 31: 17.416: E / Android Random (13385): Android. App ActivateTrade.Mine (ActivityTrad.Java 4424) 08-01 14: 31: 17.416: E / Android Time (13385): Java.lang.reflect.Method.invokeNative at (original method) 08-01 14: 31: 17.416: E / AndromedaTime (13385): at java.lang.reflect.Method.invoke (Method 11.Pass 11) 08- 01 14: 31: 17.416: E / Android Random (13385): com.android.internal.os.ZygoteInit $ MethodAndArgsCaller Run (ZygoteInit.java:784) 08-01 14: 31: 17.416: E / Android Time (13385): Internal.os.ZygoteInit.main on Com.android (Geogotinet. Java 5151) 08-01 14: 31: 17.416: E / Android Rendime (13385): Dlvic. System Netstart.mine (default method)
I checked with the debugger and all the parameters are being passed correctly. The SQLite browser shows that I have the same table with these parameters Have a record.
The table was created in the DB_Helper class:
// create the selected group of groups string create_table_selected_groups = "create tab" + Constants.Table_Names.TABLE_NAME_SELECTED_GROUPS + "(_ID primary primary Antoinecrum "+", trip_id INTEGER, group_id INTEGER); "; Db.execSQL (create_table_selected_groups);
Why is not being returned? What is the problem with this code?
What do you want and
operator works on binary numbers and = < There is more cooperative than / code>.
AND
:
"trip_id =" + Trip_id + "and group_id =" + group_id
Comments
Post a Comment