java - NullPointerException from FileHelper class downloaded from github -


i'm following video guide/tutorial make self destructing message app android treehouse. things going great until downloaded filehelper class github (written guys in video guide).

now when run app , try send message backend after selecting photo/video via device's gallery, works fine, when select photo/video devices camera crashes , nullpointerexception in logcat.

04-16 19:35:19.007: e/androidruntime(6299): fatal exception: main  04-16 19:35:19.007: e/androidruntime(6299): java.lang.nullpointerexception  04-16 19:35:19.007: e/androidruntime(6299):     @       com.pbg.swapzy.filehelper.getbytearrayfromfile(filehelper.java:27)  04-16 19:35:19.007: e/androidruntime(6299):     @    com.pbg.swapzy.recipientsactivity.createmessage(recipientsactivity.java:159)  04-16 19:35:19.007: e/androidruntime(6299):     @      com.pbg.swapzy.recipientsactivity.onoptionsitemselected(recipientsactivity.java:122)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.app.activity.onmenuitemselected(activity.java:2606)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.policy.impl.phonewindow.onmenuitemselected(phonewindow.java:1045)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.view.menu.menubuilder.dispatchmenuitemselected  (menubuilder.java:735)  04-16 19:35:19.007: e/androidruntime(6299):     @      com.android.internal.view.menu.menuitemimpl.invoke(menuitemimpl.java:149)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.view.menu.menubuilder.performitemaction(menubuilder.java:874)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.view.menu.actionmenuview.invokeitem(actionmenuview.java:592)  04-16 19:35:19.007: e/androidruntime(6299):     @   com.android.internal.view.menu.actionmenuitemview.onclick(actionmenuitemview.java:149)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.view.view.performclick(view.java:4222)  04-16 19:35:19.007: e/androidruntime(6299):     @      android.view.view$performclick.run(view.java:17273)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.os.handler.handlecallback(handler.java:615)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.os.handler.dispatchmessage(handler.java:92)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.os.looper.loop(looper.java:137)  04-16 19:35:19.007: e/androidruntime(6299):     @  android.app.activitythread.main(activitythread.java:4895)  04-16 19:35:19.007: e/androidruntime(6299):     @  java.lang.reflect.method.invokenative(native method)  04-16 19:35:19.007: e/androidruntime(6299):     @  java.lang.reflect.method.invoke(method.java:511)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:994)  04-16 19:35:19.007: e/androidruntime(6299):     @  com.android.internal.os.zygoteinit.main(zygoteinit.java:761)  04-16 19:35:19.007: e/androidruntime(6299):     @  dalvik.system.nativestart.main(native method) 

here code in question

public static byte[] getbytearrayfromfile(context context, uri uri) {     byte[] filebytes = null;     inputstream instream = null;     bytearrayoutputstream outstream = null;      if (uri.getscheme().equals("content")) {         try {             instream = context.getcontentresolver().openinputstream(uri);             outstream = new bytearrayoutputstream();              byte[] bytesfromfile = new byte[1024*1024]; // buffer size (1 mb)             int bytesread = instream.read(bytesfromfile);             while (bytesread != -1) {                 outstream.write(bytesfromfile, 0, bytesread);                 bytesread = instream.read(bytesfromfile);             }              filebytes = outstream.tobytearray();         }         catch (ioexception e) {             log.e(tag, e.getmessage());         }         {             try {                 instream.close();                 outstream.close();             }             catch (ioexception e) { /*( intentionally blank */ }         }     }     else {         try {             file file = new file(uri.getpath());             fileinputstream fileinput = new fileinputstream(file);             filebytes = ioutils.tobytearray(fileinput);         }         catch (ioexception e) {             log.e(tag, e.getmessage());         }     }      return filebytes; } 

line 27

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

thanks help!

edit getbytearrayfromfile used in code

protected parseobject createmessage() {     parseobject message = new parseobject(parseconstants.class_messages);     message.put(parseconstants.key_sender_id, parseuser.getcurrentuser().getobjectid());     message.put(parseconstants.key_sender_name, parseuser.getcurrentuser().getusername());     message.put(parseconstants.key_recipient_ids, getrecipientids());     message.put(parseconstants.key_file_type, mfiletype);      byte[] filebytes = filehelper.getbytearrayfromfile(this, mmediauri);      if (filebytes == null){         return null;     }     else {         if (mfiletype.equals(parseconstants.type_image)) {             filebytes = filehelper.reduceimageforupload(filebytes);         }         string filename = filehelper.getfilename(this, mmediauri, mfiletype);         parsefile file = new parsefile(filename, filebytes);         message.put(parseconstants.key_file, file);          return message;     } } 

edit i've test code on emulator , works should, however, on real device crashes. problem test devices' camera software? app has minsdkversion 14, tagetsdk 19 , device test on 16 (4.1.2).

i'm @ total loss!

edit ran debugger , stopped @ byte[] filebytes = filehelper.getbytearrayfromfile(this, mmediauri);

everything seemed fine let run until end, works perfectly, both on device , emulator.

truly weird.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -