java - "Unhandled exception type FileNotFoundException" in JUnit, despite throwing it in normal class? -
java - "Unhandled exception type FileNotFoundException" in JUnit, despite throwing it in normal class? -
brace yourselves, java beginner here. wrote method reads file integer array list.
public static arraylist<integer> numarray(string numin) throws filenotfoundexception{ try{ filereader file = new filereader(numin); scanner sc = new scanner(file); while(sc.hasnext()) { statuscodes.add(sc.nextint()); } sc.close(); } catch(exception e) { e.printstacktrace(); } homecoming statuscodes; }
it works fine when run in main method of own class, when seek run junit test case it, gives me filenotfoundexception.
static arraylist<integer> newcodes = numarray("src/statcodes.txt");
does know how rid of exception?
there no need of declaring throws filenotfoundexception
catching exception
grab exceptions including catched , untcached(runtime) exception.
you getting filenotfoundexception
because file not found @ path have specified. maybe seek using absolute path? check root folder of project , provide path accordingly. depend running junit cases from.
java exception junit
Comments
Post a Comment