0

i got the following rawquery

private static final String DB_QUERY_GETPOS = "select f._id, F.FName, F.FArt, P.VName, O.Gebaeude, O.Raum from Faecher as F " 
                                                     + "inner join profs as P on F.Prof_ID = P._id " 
                                                     + "inner join ort as o on F.ort_id = o._id " 
                                                     + "inner join position as PO on PO.pos=? and id is not null where f._id = PO.id and PO.pos=? order by f._id;";

Why do I get ArrayOutofBounds exceptions when accessing a Cursor or ArrayList Object filled with the result of this query?

Why don't the ? params pick up the args I pass to the rawquery?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
m0rb
  • 63
  • 10
  • can you please post the code in which you access the arraylist object, and also where you send the rawquery? – John Leehey Jun 06 '11 at 22:53
  • Hi @John. I will add those lines for u when i finished work today....this is a private project and i only got the code at home. Basically the Problem is what i described in the comment at the bottom. But what i can tell u so far is that the query is just the string u see above within a rawquery call + the string array with the selection args. db.rawquery(DB_QUERY_GETPOS, String[] args); – m0rb Jun 07 '11 at 13:49

1 Answers1

1

When you work with cursors in Android, remember to use the moveToFirst function before reading the data. Otherwise it will result in ArrayOutOfBounds exceptions.

Dimse
  • 1,476
  • 1
  • 10
  • 15
  • Hi Dimse. I know how to handle cursors, that is not the Problem. The reason for the outofbounds exception is, that the Cursor (or ListArray) stays empty because the SQL rawquery is not using the arguments i pass to it which should replace the questionmarks (?) in the String u see above. When i put in some fix integers...it works fine. – m0rb Jun 07 '11 at 13:45
  • First i can see from the documentation that the SQL statement must not end with ';'. (http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[])) Perhaps it has something to do with the string being final? Maybe that creates problems for the replacement code? – Dimse Jun 07 '11 at 16:47
  • Hi Dimse ! I can't believe that i didn't see this myself... :-) I guess sometimes if you have too many possibilities for a bug, you don't see the most obvious ones.... thx for the hint ;-) I removed the "final" and it works perfectly lol – m0rb Jun 07 '11 at 20:04