• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting real path from an image uri after camera and uploading-getting null pointer exception

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an app that is just a webview with a button overlayed(shows up onyl in certain situations. it opens the camera, takes the picture an saves it BUT only if i comment out the whole ftp part(the real issue is i am getting a nullpointer exception in getrealpathfromuri). but WHY! I have the real path being output to logcat and its fine.

 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

You say you're getting a NullPointerException, but where exactly? Could you post the stack trace?
 
rod manssou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:Welcome to JavaRanch!

You say you're getting a NullPointerException, but where exactly? Could you post the stack trace?



Hi! Thanks for the greeting! I am getting the NPE in the getRealPathFromURI(uri) method. But i do not know why. logcat shows the output of System.out.prinln(picUri) as file:///mnt/sdcard/xxx.jpg (even though there is no sdcard and it ends up in the root directory which is fine).
but when i call getRealPathFromUri(picUri) I get a NPE at "int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);"
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, that's not a stack trace, but at least you narrow it down to the line that's causing the problem. So either cursor is null, or the NPE comes from the method getColumnIndexOrThrow(). Can you check if cursor is null? Or just post a stack trace.
 
Saloon Keeper
Posts: 7597
177
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't ever do this:


catch (IOException e)
{
}


You simply must handle I/O exceptions, you can't just proceed as if nothing has happened. You should also log the exception message.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic