java - Android Studio - FileNotFound exception in editor -


i'm getting error in android studio ide before hitting "run".

unhandled exception: java.io.filenotfoundexception

with class:

(the function in class not yet being called!)

import java.io.*;   public class fileio { public static byte[] readbinaryfilefromassets(file file) {     byte[] data = null;      datainputstream dis = new datainputstream(new fileinputstream(file));     dis.readfully(data);     dis.close();      return data; } } 

thanks.

its bothering because haven't handled potential file not found exception. surround try/catch or throw exception.

 public static byte[] readbinaryfilefromassets(file file)     {         byte[] data = null;          datainputstream dis = null;         try {             dis = new datainputstream(new fileinputstream(file));             dis.readfully(data);             dis.close();         } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }           return data;     } 

note: can automatically surround blocks in try/catch in android studio doing alt+enter bring options , selecting "surround try/catch"


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -