Applet not running on the web


E

emf

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?

Thanks,

Eustace
 
Ad

Advertisements

A

Arne Vajhøj

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?


Do you see anything in Java console?

Arne
 
A

Arne Vajhøj

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?


Ooops.

#FileReader ephemeris = new FileReader("transits/ephemeris.csv");

applets run client side!

The user do not have a transits/ephemeris.csv file and the
applet would not have priv to access it anyway.

Stuff your class files *and* the CSV file in a jar
file and let the Java code retrieve the CSV as a resource!

Arne
 
E

emf

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?


Ooops.

#FileReader ephemeris = new FileReader("transits/ephemeris.csv");

applets run client side!

The user do not have a transits/ephemeris.csv file and the
applet would not have priv to access it anyway.


Really?! I would think that the application would look at the server for
the file... But why didn't it give catch the error?
Stuff your class files *and* the CSV file in a jar
file and let the Java code retrieve the CSV as a resource!

Arne

I will try your suggestion and get back to the newsgroup with the results.

Thanks,

Eustace
 
E

emf

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?


Do you see anything in Java console?

Arne


I didn't check, but instead of catching IOException, I switched to
catching Exception, and printing in the textArea, and then I started
seeing SecurityException. See next reply.

emf
 
E

emf

The webpage is:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/jv/transits/NatalTransitsApplet.java

The applet was working without a problem from the beginning in the
eclipse applet viewer. Then I managed to make it work on browser from my
computer by putting the class and the csv files into a transits folder
(like the package in eclipse) and the html in the higher level
directory. Then I created the same structure in the webserver. The
applet loads, when you enter a invalid birthdate it lets you know, but
when you enter a valid birthdate it seems that it does nothing. I tried
to troubleshoot adding JOptionPanes, and the problem seems to be in the
planet array method:

// array of date, planet position formatted to integer, and in minutes
public int[][] planetArray(String birthday$) {
int i = 0;
String textLine = null;
int[][] planetArray = new int[36525][2];
try {
FileReader ephemeris = new FileReader("transits/ephemeris.csv");
BufferedReader buffer = new BufferedReader(ephemeris);
String date;
do {
textLine = buffer.readLine();
date = textLine.substring(0, 8);
i++;
} while (!date.equals(birthday$));
for (i = 0; i < 36525; i++) {
planetArray[0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[1] =
toMinutes(textLine.substring(planetPlace,planetPlace
+ 5));
textLine = buffer.readLine();
if (textLine == null) {
break;
} //the remaining places of the array are 0
}
buffer.close();
} catch (IOException e) {
outputArea.setText("Invalid date input.");
outputArea.append("\n" + e.toString());
}
return planetArray;
}

but the try block does not catch any errors. What could the problem be?


Ooops.

#FileReader ephemeris = new FileReader("transits/ephemeris.csv");

applets run client side!

The user do not have a transits/ephemeris.csv file and the
applet would not have priv to access it anyway.

Stuff your class files *and* the CSV file in a jar
file and let the Java code retrieve the CSV as a resource!

Arne


Unfortunately the suggested solutions does not work. I have both
versions on the server:

https://files.nyu.edu/emf202/public/jv/NatalTransitsA.html

uses the jar archive, while

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

uses the transits folder.

Both work fine in my browser when running from the local files, but when
running through the Internet they both give a
java.security.AccessControlException, after using

catch (e Exception)

The code is here

https://files.nyu.edu/emf202/public/jv/NatalTransitsApplet.java

What is done is similar cases?

Eustace
 
Ad

Advertisements

L

Lew

emf said:
Unfortunately the suggested solutions does not work. I have both

What happens when you try it?

What's the structure of the app inside the JAR?

Where in the JAR did you put the CSV?

How is the code attempting to retrieve the CSV?

I sure hope you aren't calling 'new FileReader()' to get to it!

Oh!

'FileReader ephemeris = new FileReader("transits/ephemeris.csv");'

That's not how you read it. Use 'getResourceAsStream()' and put a
'StreamReader' around it.

See the Javadocs for 'Class said:
versions on the server:

httÏs://files.nуu.edц/emf202/public/jv/NatalTransitsA.html

uses the jar archive, while

httÏs://files.nуu.edц/emf202/public/jv/NatalTransits.html

uses the transits folder.

Both work fine in my browser when running from the local files, but when

Probably because the JAR version can still see the file system.
running through the Internet they both give a
java.security.AccessControlException, after using

Probably because you still haven't changed the code to comply with
Arne's suggestion.

Additional comments:

- Don't use TAB characters to indent code for public consumption.
- For Christ's sake, man, Javadoc your code!
- 'String textLine = null;' Don't assign values you will never use.
- 'String textLine = null;' declared at too broad a scope.
- 'catch (Exception e)' is far too broad. Catch the particular exceptions.
- 'String birthday$' Never use '$' in your variable names. Ever.
It's for system-generated stuff only.
Follow the naming conventions in the Java Coding Conventions.
- 'int[][] planetArray' Generally, variable names should not indicate their
implementation but their purpose.
- 'int[][] planetArray' not the best type. You're storing what are essentially
strings there, as 'int' values. You can invent your own type if 'String'
doesn't suffice.
- 'planet1 = (planet1 - planet2 > 21540) ? ...' Magic numbers are bad.
- 'package transits;' Good.
 
E

emf

Applets may not do i/o, otherwise they could snoop on the hard disks
of strangers out of the net running them. You must put your classes
in a jar and sign it.

See http://mindprod.com/jgloss/signedapplets.html
http://mindprod.com/jgloss/applet.html

Hmm... All this seems too complicated and still not quite satisfactory.
It might be simpler to suggest that the visitor, if sufficiently
interested, download the files and run the program in his/her own
computer instead. I'll have to check Lew's suggestions first.

emf
 
R

Roedy Green

All this seems too complicated and still not quite satisfactory.
It might be simpler to suggest that the visitor, if sufficiently
interested, download the files and run the program in his/her own
computer instead.

I give my Applets a main method so they can be run from the command
line. You still want to bundle classes in jars, even if you do not
sign.

see http://mindprod.com/jgloss/jarexe.html
 
Ad

Advertisements

A

Arne Vajhøj

Applets may not do i/o, otherwise they could snoop on the hard disks
of strangers out of the net running them. You must put your classes
in a jar and sign it.

If the CSV file is server side, then it is neither necessary
nor help.

Arne
 
A

Arne Vajhøj

Unfortunately the suggested solutions does not work.

It works. It has been used thousands of times before.
I have both
versions on the server:

https://files.nyu.edu/emf202/public/jv/NatalTransitsA.html

uses the jar archive, while

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

uses the transits folder.

Both work fine in my browser when running from the local files, but when
running through the Internet they both give a
java.security.AccessControlException, after using

catch (e Exception)

The code is here

https://files.nyu.edu/emf202/public/jv/NatalTransitsApplet.java

You are still using:

#FileReader ephemeris = new FileReader("transits/ephemeris.csv");

I said:

#and let the Java code retrieve the CSV as a resource

So you need code like:

Reader ephemeris =
new
InputStreamReader(getClass().getClassLoader().getResourceAsStream("transits/ephemeris.csv")));

and the file needs to be "transits/ephemeris.csv" within the jar file.

Arne
 
E

emf

What happens when you try it?

What's the structure of the app inside the JAR?

Where in the JAR did you put the CSV?

How is the code attempting to retrieve the CSV?

I sure hope you aren't calling 'new FileReader()' to get to it!

Oh!

'FileReader ephemeris = new FileReader("transits/ephemeris.csv");'

That's not how you read it. Use 'getResourceAsStream()' and put a
'StreamReader' around it.



Probably because the JAR version can still see the file system.


Probably because you still haven't changed the code to comply with
Arne's suggestion.

Additional comments:

- Don't use TAB characters to indent code for public consumption.
- For Christ's sake, man, Javadoc your code!

I haven't yet started using the Javadoc eclipse feature. Coming soon.
- 'String textLine = null;' Don't assign values you will never use.

This happens when during the program development the compiler complaints
that a variable has not been initialized, so you initialize it. In later
stages of the development you change the code so the initialization is
superfluous - though it doesn't hurt. At still later stage you may
realize that it is superfluous, and you remove it.
- 'String textLine = null;' declared at too broad a scope.
- 'catch (Exception e)' is far too broad. Catch the particular exceptions.

If I had used catch (Exception e) from the beginning instead of
IOException, I would have known what was wrong a couple of days earlier.
So, from bitter experience, I learned that it is wise to use Exception,
until at a later stage, when everything is working OK, you may return
and change it, as an icing on the cake.
- 'String birthday$' Never use '$' in your variable names. Ever.
It's for system-generated stuff only.

That was from my good old QBasic days... And I thought it was such a
great idea! Pity. Anyway, I replaced $ with S when necessary.
Follow the naming conventions in the Java Coding Conventions.
- 'int[][] planetArray' Generally, variable names should not indicate their
implementation but their purpose.

Since I learned about it, I enjoy Refactoring class, method, and
variable names. I will change it when I think of an appropriate one.
- 'int[][] planetArray' not the best type. You're storing what are essentially
strings there, as 'int' values. You can invent your own type if 'String'
doesn't suffice.

Ok, I made it String array, and the code is actually simpler now.
- 'planet1 = (planet1 - planet2 > 21540) ? ...' Magic numbers are bad.

360° * 60' = 21600'. From 29PI00 to 01AR00 it's 2°, not 358°. I added a
comment.
- 'package transits;' Good.

As I've said, with the jar I can have everything in the same folder, so
if eclipse wants to use packages I do not mind.

The new program:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

and the code

https://files.nyu.edu/emf202/public/jv/NatalTransitsApplet.java

I am grateful that you took the time to correct my mistakes and help me
effectively in improving my code.

Regards,

Eustace
 
E

emf

It works. It has been used thousands of times before.


You are still using:

#FileReader ephemeris = new FileReader("transits/ephemeris.csv");

I said:

#and let the Java code retrieve the CSV as a resource

So you need code like:

Reader ephemeris =
new
InputStreamReader(getClass().getClassLoader().getResourceAsStream("transits/ephemeris.csv")));


and the file needs to be "transits/ephemeris.csv" within the jar file.

Arne

Arne, the line of code is marvelous! I rechecked the 3 Java books (2 of
which I've read through, and 2 of them are over 600p long) and
recreating all the code, and they do not have it. That's why these
newsgroups are invaluable. Sometimes, of course, you can find answers by
googling them, but not always.

Thanks to you, the final product:

https://files.nyu.edu/emf202/public/jv/NatalTransits.html

Still I have to reread some chapter Tarnas' book, and add a paragraph or
2 of what exactly to look for. But the preset Saturn return with 5° orb
is very convincing if you've at least 28-29 years old, and even more if
you are 60, while the Neptune aspects are rather elusive.

Thanks,

Eustace
 
Ad

Advertisements

A

Arne Vajhøj

Arne, the line of code is marvelous! I rechecked the 3 Java books (2 of
which I've read through, and 2 of them are over 600p long) and
recreating all the code, and they do not have it. That's why these
newsgroups are invaluable. Sometimes, of course, you can find answers by
googling them, but not always.

The getResource/getResourceAsStream from applet technique should be
in any detailed description of applets. It is in the Java tutorial.

The problem may be that most examples are for graphical images
not text.

Arne
 
Ad

Advertisements


Top