2

I'm on my first week using Java. I don't know very much about applets, and I'm trying to learn more using a book. I've already done some applets that contain simple animation, but when I tried drawing an image I've got stock on this:

access denied( "java.io.FilePermission" "[image]" "read").

Anyone who can help me?

    import java.awt.Graphics;
    import java.awt.Image;

    public class Wave extends java.applet.Applet{

        Image waveimg;

        public void init(){

            waveimg=getImage(getCodeBase(),"wave.jpg");

        }

        public void paint(Graphics g){

            g.drawImage(waveimg, 10,10,this);

        }
  }
HassanF
  • 465
  • 1
  • 6
  • 13
Andreea
  • 21
  • 1
  • 1
  • 2
  • Most likely, the applet or its container does not have permission to read from the provided URL. See if you can get to draw an image available through a publicly accessible URL. – npinti Jul 28 '15 at 12:13
  • @Andreea if one of the Answers solved your problem, then please select one to close this question :) – Kami Jul 28 '15 at 23:46
  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Jul 29 '15 at 12:02
  • `access denied( "java.io.FilePermission" "[image]" "read").` How are you loading the applet? Using applet viewer? Using the some HTML loaded off the local file system in the default browser? Using some HTML loaded off a local server in the default browser? This information might make all the difference about when the applet will succeed or fail. – Andrew Thompson Jul 29 '15 at 12:07

2 Answers2

1

This is because Applets need permissions to read/write from/to files. Maybe this page can help you: How Can An Applet Read Files On The Local File System

Kami
  • 459
  • 1
  • 6
  • 27
  • *"Applets need permissions to read/write from/to files."* Not to load files, or at least, not when loading them from the same site using `getImage(getCodeBase(),..);` – Andrew Thompson Jul 29 '15 at 12:03
0

You have to give your applets the permission to read/write the images.

Refer this link to grant access to it. http://docs.oracle.com/javase/tutorial/security/tour1/wstep2.html

Loganathan Mohanraj
  • 1,736
  • 1
  • 13
  • 22