Get File Path With URI

by Bobbie » Thu, 02 Apr 2009 02:11:54 GMT


Sponsored Links
 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);
}

--~--~---------~--~----~------------~-------~--~----~



Get File Path With URI

by Mark Murphy » Thu, 02 Apr 2009 02:13:47 GMT


 


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!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Get File Path With URI

by Mark Murphy » Thu, 02 Apr 2009 02:14:56 GMT


 


Actually, to clarify: Cursors are always pointing before the first
result when you initially get the Cursor from a query (whether of a
content provider or database).

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

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

--~--~---------~--~----~------------~-------~--~----~



Get File Path With URI

by Bobbie » Thu, 02 Apr 2009 02:39:34 GMT


 Thank you SO much!  I hate those 1-liners that kill your app, haha.
Thanks again!!!






--~--~---------~--~----~------------~-------~--~----~



Get File Path With URI

by GeorgKitz » Mon, 27 Apr 2009 22:08:34 GMT


 Does your code work?
I have exactly the same source and i'm setting the cursor to the first
element.

The only problem is that my latitutde-value is always 0. But the image
has EXIF information about the location in it.

Can somebody help me?

Regards Georg




--~--~---------~--~----~------------~-------~--~----~



Get File Path With URI

by Sergey Ten » Tue, 28 Apr 2009 01:05:19 GMT


 After query returns the cursor, it has to be moved forward. It can be done
as follows:

   ContentResolver cr = getContentResolver();
   Cursor cursor = cr.query(photoUri, new String[] {
           MediaStore.Images.


if (cursor != null && cursor.getCount() > 0) {
    cursor.moveToFirst();
    long fname = cursor.getLong(cursor.

}

Sergey






--~--~---------~--~----~------------~-------~--~----~



Get File Path With URI

by Georg » Thu, 30 Apr 2009 05:32:59 GMT


 ou are right, I know these things, but thats not the problem.

The problem is that i always get 0.0 for the Latitude and Longitude
column.
That's the problem.
Any ideas?

Regards Georg

On Apr 27, 7:05pm, Sergey Ten <sergeyte...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Starting Google Maps at pre-specified location

Hi Group,

I have one problem with Google Maps, while opening them at some
location. How could that be possible for user to specify city first
(e.g. type in EditText field "London") then press a button and see
London on the map? I've succeded in opening GMaps at some pre-
specified location, but only using coordinates:(. Cannot find anything
on topic.

Thanks in advance!

Denis

2. self steering car using Camera.

Any interest in building a self-steering car using Android camera?
See block diagram here.
http://docs.google.com/View?id=dz28fm9_129gxg6sfgn
Sorry, slightly off topic...
Jim

3. Triggering dynamically a NUMERIC keyboard with no use of TextView component.

4. Problem with ListPreference in preference view

5. is there a way to know exclude the invisible face intersected with a pick ray?

6. Query ringtone???

7. Making Kernel Crash -Ramdump/Crash-Emulator on windows