Bobbie wrote:
> I am launching an image picker (from the gallery) and my code crashes
> every single time.  I tried to get some help in another post, but
> people quit responding to the post.  Please help.  When I do a debug,
> it tells me this (there are TONS of errors, but these looked the most
> important - also, I changed the "com.app.name/com.app.name.activity"
> for privacy reasons):
> 
> 04-01 14:09:30.254: WARN/dalvikvm(719): threadid=3: thread exiting
> with uncaught exception (group=0x4000fe68)
> 04-01 14:09:30.254: ERROR/AndroidRuntime(719): Uncaught handler:
> thread main exiting due to uncaught exception
> 04-01 14:09:30.274: ERROR/AndroidRuntime(719):
> java.lang.RuntimeException: Failure delivering result ResultInfo
> {who=null, request=1, result=-1, data=Intent { data=content://media/
> external/images/media/7 }} to activity {com.app.name/
> com.app.name.activity}:
> android.database.CursorIndexOutOfBoundsException: Index -1 requested,
> with a size of 1
> 04-01 14:09:30.274: ERROR/AndroidRuntime(719): Caused by:
> android.database.CursorIndexOutOfBoundsException: Index -1 requested,
> with a size of 1
> 
> Here is the code that invokes the activity, follwed by the code that
> is invoked after the activity has finished:
> 
> public void takePic() {
>               Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
>               photoPickerIntent.setType("image/*");
>               startActivityForResult(photoPickerIntent, 1);
> }
> 
> @Override
> protected void onActivityResult(int i, int j, Intent intent)
> {
>     super.onActivityResult(i, j, intent);
> 
>     Uri photoUri = intent.getData();
> 
>     ContentResolver cr = getContentResolver();
>     Cursor cursor = cr.query(photoUri, new String[] {
>             MediaStore.Images.ImageColumns.LATITUDE,
>           MediaStore.Images.ImageColumns.LONGITUDE
>      }, null, null, null);
> 
>     long fname = cursor.getLong(cursor.getColumnIndexOrThrow
> (MediaStore.Images.ImageColumns.LATITUDE));
> 
>     chatscreen.append("File Name: "+fname);
> }
> 

Cursors are always pointing before the first result. You need to call
moveToFirst() on your cursor before calling getLong(). You should also
check to make sure that you got at least one result (e.g.,
!cursor.isAfterLast()) before calling getLong().

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to