aspose file tools*
The moose likes Applets and the fly likes Java Applet image I/O exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Java Applet image I/O exception" Watch "Java Applet image I/O exception" New topic
Author

Java Applet image I/O exception

Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
i have an issue with my java applet ive been developing, everything is fine and working wonderfully in the IDE (eclipse) however once i take the class files out and put the two of them in the same folder with all the images and use a HTML file to run it it opens then the java console comes up and has this exception:-

Exception in thread "Thread-12" java.security.AccessControlException: access denied ("java.io.FilePermission" "Background.png" "read")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.canRead(Unknown Source)
at javax.imageio.ImageIO.read(Unknown Source)
at gameLoop.run(gameLoop.java:27)
at java.lang.Thread.run(Unknown Source)
ive looked everywhere and i dont know what to do my sorce code is below

game:
Code:

gameLoop
Code:

my HTML file:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>The Adventures Of Marmalade</title>
<style type="text/css">
body { color: white; background: black }
</style>
</head>
<body>
<div>
<h1 align="center">The Adventures Of Marmalade</h1>
<applet code=Game.class width=854 height=480>


Sorry, you need a Java-enabled browser to run this applet.


</applet>
</div>
</body>
</html>



i would attach the images but there are alot of them, im sure there is just something ive missed or i have gone the wrong way about something, if anyone has an answer please help thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your code attempts to read images from the client's file system. That isn't what you want -- clearly the user of your applet isn't going to have those files installed on their machine. You want to read them from the server where the applet was downloaded from.

The standard way to get an image in an applet is to use Applet's getImage(URL) method. Notice that it requires a URL. You can start with the URL returned by the getCodeBase() method of Applet, and then get a URL relative to that one which refers to your image.

That means that your applet is going to be downloading images from your web site, so make sure that you put the images in the right place for them to be downloaded.
Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
okay can you show me how to use the getImage function properly then? because what ive guessed at hasent worked thank you for the quick reply
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Let's start with your guess, then. Even if it doesn't work, it's possible it just needs a bit of fixing.
Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7

im using serif web designer to test it out given i havent as of yet purchased a domain and hosting services, this wont affect it will it? even so it still comes up with the same error, ive put it in the file thats their im hoping that would work
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, null is the wrong thing to use for the first parameter. I would start out with



What that means is, let's suppose that the URL for your applet is "http://yourhost.com/Game.class" -- i.e. that's where the browser finds it. Then that means you're saying that
the image will be found at the URL "http://yourhost.com/root/wpimages/Background.png". If that isn't the case, then adjust the parameters until you have it right.

This is just basic HTTP, so it's going to apply to both your test environment, the one you're using now, and any real-life server you might install it on in the future.
Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
okay no error anymore console comes up normally and no exception errors, however nothing shows up on screen? is just white space?? ill send the new code and a screen print of the file managing

gameLoop:-
Code:


[Thumbnail for cm.utemp.png]

Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
okay you cant actually read that so ill type it out

root:-
wpimages:-
(my images are in here)
wpiscripts
(nothing)
Game.class
gameLoop.class
index.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm a bit confused about the fact that you have two separate applets (Game and gameLoop) and one extends the other. That's quite unorthodox.

And then your HTML loads the Game applet, whereas you seem to be expecting the gameLoop applet to be loaded. So as I say, I don't understand what's going on there.
Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
okay ive merged everything now, and using getImage but im still getting just a blank screen, is this because it cannot find it??

Code:
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I dunno. What do the error messages say? You'll find them in the Java console.
Thomas Sweetman
Greenhorn

Joined: Sep 27, 2012
Posts: 7
there arnt any, thats whats confuseing me... ive tried putting in a trace with System.out.println but it dosent show up, it may just be a HTML issue now rather than java...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

Continued at animation not working?? -- Java Forums


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Applet image I/O exception