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. How can I use IM app in 1.5

Hi,

IM app doesn't appeared in cupcake 1.5

I changed the make file, So IM.apk installed.

Buf it doean't appeared yet.

I think there isn't plugin information about server connection.

If I use MSN, how can I set the plugin information.

thank you

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

2. getting location name from lat, lon

hello everybody

Is there any API method{[android.location " pack ] to get location
name?
did not find related method to to retrieve location name for given
GeoPoint(lat,lon);

I wanted to keep list of location names for particular GeoPoints
(lat,Lon)
in journey.

can this be achievable in Android to calculate the name of location
from lat , lon. please guide for soluation.

thank you



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

3. Sending Email using android app

4. apk manual install problem Failure [-12]

5. How can I get the logging ID gmail

6. what is tag/branch for SK 1.5_r1

7. "automatic location finder"