Java input == null why? -
i'm using simple way resources project. i'm using eclipse, , have 'res' folder hold needed files. how load stuff, example 'puppy.png' in res folder (no subfolders):
string path = "/puppy.png"; try { bufferedimage image = imageio.read(getclass().getresourceasstream(path)); } catch(exception ex) { ex.printstacktrace(); }
and input==null error, , sometiomes not! not time puppy.png loaded next time won't. classes loads correctly, , other classes error. can explain why can happen, , how can fix it, still use getresourceasstream() method?
please have @ how retrieve image project folder?.
i have mentioned no of ways read image different paths.
you can try one
// read same package imageio.read(getclass().getresourceasstream("c.png")); // read absolute path imageio.read(new file("e:\\software\\trainpis\\res\\drawable\\c.png")); // read images folder parallel src in project imageio.read(new file("images\\c.jpg"));
in case image must in same package class , don't prefix /
.
Comments
Post a Comment