AccessControlException when running with applet

L

laxcompute

Hello-

I've been using Java for quite a while, but I'm fairly new to applets.

I wrote my main program, as a panel and several other classes. Then I
made a driver to run it. It works fine that way, but I'm trying to
eventually get my program onto a webpage. So, I made an applet to call
the Panel, instead of the driver.

When I run the Applet, I get the following message:

However, it works just fine when I run the driver. All of my files are
in the same folder.

Here is the code for the applet:

import javax.swing.JApplet;
public class AppletPotter extends JApplet
{
public void init()
{
try{
setContentPane(new PanelPotter(6,5,6,12));
}
catch(Exception e){
return;
}
}
}

Here is the code for the driver:

import javax.swing.JFrame;
public class DriverPotter
{
public static void main(String[] args) throws Exception
{
JFrame frame = new JFrame("The Game");
frame.setSize(600,440);
frame.setLocation(100,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new PanelPotter(6,5,6,12));
frame.setVisible(true);
}
}

And, here is the initialization and construction of the Panel:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.xml.parsers.*;

public class PanelPotter extends JPanel
{
private static TextField input;
private static TextArea output;
private static Button go;
private static JScrollPane scroller;
private static int xCenter, yCenter, xPos, yPos, xStart, yStart;
private static Location[][] locations;

public PanelPotter(int xC, int yC, int xS, int yS) throws
Exception
{
locations = LocationReader.toArray("locations.xml");
xCenter = xC;
yCenter = yC;
xStart = xPos = xS;
yStart = yPos = yS;
this.setLayout(new BorderLayout());
try{
output = new TextArea(">>"+locations[xStart]
[yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
}
catch(Exception e){
System.out.println("caught");
return;
}
output.setSize(490,340);
output.setVisible(true);
output.setEditable(false);

input = new TextField();
input.setVisible(true);
input.addKeyListener(new Texter());

add(input, BorderLayout.SOUTH);
add(output, BorderLayout.CENTER);
}

As you can see, my problem happens on this line: output = new
TextArea(">>"+locations[xStart][yStart].getReply("look around")+"\n",
50,20,TextArea.SCROLLBARS_VERTICAL_ONLY);

locations is an array which I read from an XML file, using several
other bits of code. If you need to see them to help with this problem,
just let me know what you need.

Does anyone know how to fix this problem?

Thank you very much!
 
D

Daniele Futtorovic

Hello-

I've been using Java for quite a while, but I'm fairly new to applets.

I wrote my main program, as a panel and several other classes. Then I
made a driver to run it. It works fine that way, but I'm trying to
eventually get my program onto a webpage. So, I made an applet to call
the Panel, instead of the driver.

When I run the Applet, I get the following message:

The error is quite plain, really: you do not have the rights to access
(read) the user's home directory.
locations is an array which I read from an XML file, using several
other bits of code. If you need to see them to help with this problem,
just let me know what you need.

You want to run your code as an Applet (i.e. no installation), yet
you're depending on a specific file to be present on the user's machine?
That doesn't make sense.

If, on the other hand, that file is global (i.e. not specific to a
user), then it will still be on your server. The Applet, however, gets
executed on the client's machine. You'll have to get the information
from the former to the latter.
Either query the file via a network call (HTTP, FTP, whatever), or maybe
embed it into your program as a class, or... there may be more
possibilities. The first one is probably the most straightforward in
terms of update-ease and maintainability.

DF.
 
L

laxcompute

The error is quite plain, really: you do not have the rights to access
(read) the user's home directory.

You want to run your code as an Applet (i.e. no installation), yet
you're depending on a specific file to be present on the user's machine?
That doesn't make sense.

If, on the other hand, that file is global (i.e. not specific to a
user), then it will still be on your server. The Applet, however, gets
executed on the client's machine. You'll have to get the information
from the former to the latter.
Either query the file via a network call (HTTP, FTP, whatever), or maybe
embed it into your program as a class, or... there may be more
possibilities. The first one is probably the most straightforward in
terms of update-ease and maintainability.

DF.

Well, right now all of the files are just on my computer, in the same
folder. Not on a webpage yet.

So, it will be global, and I'll just have the XML file on my webpage.

Right now though, I'm just running Applet Viewer with my applet.

But thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top