• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
rod manssou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.

 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Moores
Bartender
Posts: 2946
46
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic