Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Sending Messages Sending the Message

Problem with FileHelper line:27

Hello App crashes when I try to send a message. It seems that problem is with FileHelper class.

06-13 09:40:53.405 1221-1221/? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at shining.is.sun.ribbit.FileHelper.getByteArrayFromFile(FileHelper.java:27)

I commented this line: //fileBytes = FileHelper.reduceImageForUpload(fileBytes);

And app is working. But I still would like file reduction to work. And I'd like to know what the problem is.

3 Answers

Looks like the fileBytes may not be initialized correctly it should be.

byte[] fileBytes = FileHelper.getByteArrayFromFile(this, mMediaUri)

if you have set it this way I would then look at the mMediaUri variable and how you have initialized that.

Hi, David!

Thanks for your answer. fileBytes is initialized correctly (exactly the same as in your post).

mMediaUri initialized insine onCreate() method by:

mMediaUri = getIntent().getData();

By the way, line27 in FileHelper class is:

   if (uri.getScheme().equals("content")) {

You are getting a null exception which means the mMediaUri is null when you call the getByteArrayFromFile() method. So when the FileHelper runs line 27 it can't get the uri scheme because the uri is null.

I would check the mainActivity where the data for the intent is set, you could also insert a Log.i line in the recipentsActivity to see what the value of mMediaUri is once it has been initialized.

If you still can't find what is causing the problem download the project files and compare your code with that.

Let me know if this helps.

Hi David! First of all, thanks for your help!

Pretty strange thing happened. First I inserted Log line and found, that mMediaUri is null. Then I inserted Logs to other parts of code, where mMediaUri was initialized nad passed. Suddenly mMediaUri got the correct value )))

I didn't change a line of code (not to mention Logs). And it started working. Maybe it was some IDE bug or Genymotion bug. I don't know.

Anyway, thank you David!

Glad I could help