Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Applet not running on the web (http://www.velocityreviews.com/forums/t956225-applet-not-running-on-the-web.html)

emf 01-07-2013 12:46 AM

Applet not running on the web
 
The webpage is:

https://files.nyu.edu/emf202/public/...lTransits.html

and you can find the code in

https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
8));
planetArray[i][1] =
toMinutes(textLine.substring(planetPlace,planetPla ce
+ 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

--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/...intmebabe.html

Arne Vajhøj 01-07-2013 12:56 AM

Re: Applet not running on the web
 
On 1/6/2013 7:46 PM, emf wrote:
> The webpage is:
>
> https://files.nyu.edu/emf202/public/...lTransits.html
>
> and you can find the code in
>
> https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
> 8));
> planetArray[i][1] =
> toMinutes(textLine.substring(planetPlace,planetPla ce
> + 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



Arne Vajhøj 01-07-2013 12:58 AM

Re: Applet not running on the web
 
On 1/6/2013 7:46 PM, emf wrote:
> The webpage is:
>
> https://files.nyu.edu/emf202/public/...lTransits.html
>
> and you can find the code in
>
> https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
> 8));
> planetArray[i][1] =
> toMinutes(textLine.substring(planetPlace,planetPla ce
> + 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



emf 01-07-2013 08:39 AM

Re: Applet not running on the web
 
On 2013-01-06 19:58 Arne Vajhøj wrote:
> On 1/6/2013 7:46 PM, emf wrote:
>> The webpage is:
>>
>> https://files.nyu.edu/emf202/public/...lTransits.html
>>
>> and you can find the code in
>>
>> https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
>> 8));
>> planetArray[i][1] =
>> toMinutes(textLine.substring(planetPlace,planetPla ce
>> + 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

--
Date Calculator with all-purpose JS code
https://files.nyu.edu/emf202/public/...alculator.html

emf 01-09-2013 06:21 AM

Re: Applet not running on the web
 
On 2013-01-06 19:56 Arne Vajhøj wrote:
> On 1/6/2013 7:46 PM, emf wrote:
>> The webpage is:
>>
>> https://files.nyu.edu/emf202/public/...lTransits.html
>>
>> and you can find the code in
>>
>> https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
>> 8));
>> planetArray[i][1] =
>> toMinutes(textLine.substring(planetPlace,planetPla ce
>> + 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

--
Date Calculator with all-purpose JS code
https://files.nyu.edu/emf202/public/...alculator.html

emf 01-09-2013 06:40 AM

Re: Applet not running on the web
 
On 2013-01-06 19:58 Arne Vajhøj wrote:
> On 1/6/2013 7:46 PM, emf wrote:
>> The webpage is:
>>
>> https://files.nyu.edu/emf202/public/...lTransits.html
>>
>> and you can find the code in
>>
>> https://files.nyu.edu/emf202/public/...itsApplet.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[i][0] = Integer.parseInt(textLine.substring(0,
>> 8));
>> planetArray[i][1] =
>> toMinutes(textLine.substring(planetPlace,planetPla ce
>> + 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/...TransitsA.html

uses the jar archive, while

https://files.nyu.edu/emf202/public/...lTransits.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/...itsApplet.java

What is done is similar cases?

Eustace

--
Canto General - a folk oratorio of Mikis Theodorakis
https://files.nyu.edu/emf202/public/mt/index.html

Roedy Green 01-09-2013 06:56 AM

Re: Applet not running on the web
 
On Sun, 06 Jan 2013 19:46:39 -0500, emf <emfril@gmail.com> wrote,
quoted or indirectly quoted someone who said :

> FileReader ephemeris = new FileReader("transits/ephemeris.csv");
> BufferedReader buffer = new BufferedReader(ephemeris);


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

--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.

Lew 01-09-2013 07:01 AM

Re: Applet not running on the web
 
emf wrote:
> Arne Vajhøj wrote:
>> emf wrote:
>>> The webpage is:
>>> httρs://files.nуu.edц/emf202/ρublic/jv/NatalTransits.html
>>>
>>> and you can find the code in
>>>
>>> httρs://files.nуu.edц/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

....
>> 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!

>
> 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<T>'.

> 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.

--
Lew

emf 01-09-2013 07:46 AM

Re: Applet not running on the web
 
On 2013-01-09 01:56 Roedy Green wrote:
> On Sun, 06 Jan 2013 19:46:39 -0500, emf <emfril@gmail.com> wrote,
> quoted or indirectly quoted someone who said :
>
>> FileReader ephemeris = new FileReader("transits/ephemeris.csv");
>> BufferedReader buffer = new BufferedReader(ephemeris);

>
> 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

--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/...intmebabe.html

Roedy Green 01-09-2013 07:22 PM

Re: Applet not running on the web
 
On Wed, 09 Jan 2013 02:46:49 -0500, emf <emfril@gmail.com> wrote,
quoted or indirectly quoted someone who said :

> 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
--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.


All times are GMT. The time now is 04:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.