java NullPointerException existed Image -
what want when user selects image, image must copied specific folder , use image.
this use copy image:
files.copy( paths.get("c:/../img.png"), paths.get("c:/../src/bgs").resolve(array[array.length-1]), standardcopyoption.replace_existing);
which works fine. problem if use image after command, nullpointerexception
(i don't have problem if use thread.sleep(2500)
between 2 commands). need way check if file ready used.
so far used following code
// copy file file f = new file(new_path); sout(f.exists()); // use file image background = toolkit.getdefaulttoolkit().getimage( getclass().getresource("/bgs/img.png"));
which prints true, when use nullpointerexception
again.. ideas?
exception:
uncaught error fetching image: java.lang.nullpointerexception @ sun.awt.image.urlimagesource.getconnection(urlimagesource.java:115) @ sun.awt.image.urlimagesource.getdecoder(urlimagesource.java:125) @ sun.awt.image.inputstreamimagesource.dofetch(inputstreamimagesource.java:263) @ sun.awt.image.imagefetcher.fetchloop(imagefetcher.java:205) @ sun.awt.image.imagefetcher.run(imagefetcher.java:169)
i solved problem, in case else faced this, here did:
replace
toolkit.getdefaulttoolkit().getimage(getclass().getresource("/bgs/img.png"));
with
imageio.read(new file("bgs/img.png"));
be carefull path
"/bgs/img.png"
"bgs/img.png"
Comments
Post a Comment