Trädvy Permalänk
Medlem
Plats
Linköping
Registrerad
Jul 2010

Java applet problem

När jag försöker få in bilder in i min applet så hittar den aldrig relativa paths så har varit tvungen att skriva absolute pathen, men snart ska projektet över till en annan för koll och undrade hur jag löser problemet.

Såhär ser det ut.

try {
URL backUrl = new URL(getDocumentBase(), "Pic\\background.png");
backImg = ImageIO.read(backUrl);
} catch (Exception e) {

e.printStackTrace();
}

Får detta felmeddelande

"C:\Program Files\Java\jdk1.7.0_71\bin\java" "-Djava.security.policy=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.5\bin\appletviewer.policy" -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.5\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.7.0_71\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_71\jre\lib\ext\zipfs.jar;C:\Users\s4d\Desktop\Applet1\out\production\Applet1;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain sun.applet.AppletViewer file:/C:/Users/s4d/AppData/Local/Temp/AppletPage37.html
javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(ImageIO.java:1395)
at Main.init(Main.java:96)
at sun.applet.AppletPanel.run(AppletPanel.java:435)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: C:\Users\s4d\AppData\Local\Temp\Pic\background.png (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at java.net.URL.openStream(URL.java:1037)
at javax.imageio.ImageIO.read(ImageIO.java:1393)
... 3 more

Dold text

Den letar alltså i C:\Users\s4d\AppData\Local\Temp\Pic\background.png av någon anledning, går det att ändra detta så den letar under src istället?

Mvh

Oskar

Trädvy Permalänk
Medlem
Plats
i din garderob
Registrerad
Sep 2007

@oskkin224: Din applet anropas från en fil som ligger i Temp-mappen. Om du laddar appleten från en HTML-fil i din projektmapp istället kommer dina paths troligen fungera.

Bilanaloger är som Volvo — varenda svenne kör med dem