Applet read/write files

Hi,

I have a problem to use getCodeBase to get the URL. Actually, I am pretty confused on running the applet in our intranet.

Let me explain my problem here, I have mapped a network drive(G:\personA) in my machine and my applet and all the files are in G:\personA\classes. In my coding, I have tried to specify my files paths such as G:\personA\classes\index.txt and I can run the applet without any problem either with Eclipse or from a web site http://personA//report.html. But the other members in this company cannot run this applet thro' this web site( http://personA//report.html). The problem is "No class found", can't find the path G:\personA\classes\index.txt.

So I decided to change my code by reading/writing files thro URL i,e : http://personA/classes, but when I run my applet, I got the following exception :

ava.lang.NullPointerException

at java.applet.Applet.getCodeBase(Applet.java:136)

at web.MyChart.readAndPrintData(MyChart.java:336)

at web.MyChart<init>(MyChart.java:113)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at java.lang.Class.newInstance0(Class.java:308)

at java.lang.Class.newInstance(Class.java:261)

at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)

at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)

at sun.applet.AppletPanel.run(AppletPanel.java:298)

at java.lang.Thread.run(Thread.java:534)

does anybody knows how to solve this problem? Please...

Thanks,

Tiffany

[1848 byte] By [tiffany33a] at [2007-10-1 2:47:50]
# 1

import javax.swing.JApplet;

public class test extends JApplet {

public void init() {

System.out.println("testing for codebase");

System.out.println(getCodeBase());

System.out.println(super.getCodeBase());

System.out.println(this.getCodeBase());

}

public test() {

super();

try{

System.out.println("getCodebase doesn't work in constructor");

System.out.println(getCodeBase());

System.out.println(super.getCodeBase());

System.out.println(this.getCodeBase());

}catch(Exception e){

e.printStackTrace();

}

}

harmmeijera at 2007-7-8 15:24:34 > top of Java-index,Security,Signed Applets...
# 2
I didn't use the getCodeBase() in constructor, I use it in one of the method readAndPrintData(); I have tried many methods to run this applet in the intranet, so everybody can see my applet in the company, but I fail...anybody has any idea?Thanks, Tiffany
tiffany33a at 2007-7-8 15:24:34 > top of Java-index,Security,Signed Applets...
# 3

I think a trace would help, guessing is fun but won't solve your problem:

To turn the full trace on (windows) you can start the java console, to be found here:

C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe

In the advanced tab you can fill in something for runtime parameters fill in this:

-Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect

if you cannot start the java console check here:

C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties

I think for linux this is somewhere in youruserdir/java (hidden directory)

add or change the following line:

javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect

for 1.5:

deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect

The trace is here:

C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log

I think for linux this is somewhere in youruserdir/java (hidden directory)

harmmeijera at 2007-7-8 15:24:34 > top of Java-index,Security,Signed Applets...