Applet not running on the web

Discussion in 'Java' started by emf, Jan 7, 2013.

  1. emf

    emf Guest

    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

    --
    It ain't THAT, babe! - A radical reinterpretation
    https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
     
    emf, Jan 7, 2013
    #1
    1. Advertising

  2. On 1/6/2013 7:46 PM, emf wrote:
    > 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
     
    Arne Vajhøj, Jan 7, 2013
    #2
    1. Advertising

  3. On 1/6/2013 7:46 PM, emf wrote:
    > 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
     
    Arne Vajhøj, Jan 7, 2013
    #3
  4. emf

    emf Guest

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

    --
    Date Calculator with all-purpose JS code
    https://files.nyu.edu/emf202/public/js/dateCalculator.html
     
    emf, Jan 7, 2013
    #4
  5. emf

    emf Guest

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

    --
    Date Calculator with all-purpose JS code
    https://files.nyu.edu/emf202/public/js/dateCalculator.html
     
    emf, Jan 9, 2013
    #5
  6. emf

    emf Guest

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

    --
    Canto General - a folk oratorio of Mikis Theodorakis
    https://files.nyu.edu/emf202/public/mt/index.html
     
    emf, Jan 9, 2013
    #6
  7. emf

    Roedy Green Guest

    On Sun, 06 Jan 2013 19:46:39 -0500, emf <> 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.
     
    Roedy Green, Jan 9, 2013
    #7
  8. emf

    Lew Guest

    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
     
    Lew, Jan 9, 2013
    #8
  9. emf

    emf Guest

    On 2013-01-09 01:56 Roedy Green wrote:
    > On Sun, 06 Jan 2013 19:46:39 -0500, emf <> 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/bd/itaintmebabe.html
     
    emf, Jan 9, 2013
    #9
  10. emf

    Roedy Green Guest

    On Wed, 09 Jan 2013 02:46:49 -0500, emf <> 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.
     
    Roedy Green, Jan 9, 2013
    #10
  11. emf

    Roedy Green Guest

    On Sun, 06 Jan 2013 19:46:39 -0500, emf <> wrote,
    quoted or indirectly quoted someone who said :

    >The applet was working without a problem from the beginning in the
    >eclipse applet viewer


    see http://mindprod.com/jgloss/resource.html

    If you can put the data into the jar to be read as a resource, you can
    get around the need to sign.

    For an example of a serialised resource, see
    http://mindprod.com/products1.html#CANADIANTAX

    for an example of a text resource, see
    http://mindprod.com/products1.html#INWORDS

    --
    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.
     
    Roedy Green, Jan 9, 2013
    #11
  12. emf

    Arne Vajhøj Guest

    On 1/9/2013 1:56 AM, Roedy Green wrote:
    > On Sun, 06 Jan 2013 19:46:39 -0500, emf <> 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.


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

    Arne
     
    Arne Vajhøj, Jan 10, 2013
    #12
  13. On 1/9/2013 1:40 AM, emf wrote:
    > On 2013-01-06 19:58 Arne Vajhøj wrote:
    >> 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.


    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
     
    Arne Vajhøj, Jan 10, 2013
    #13
  14. emf

    emf Guest

    On 2013-01-09 02:01 Lew wrote:
    > 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!


    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

    --
    Date Calculator with all-purpose JS code
    https://files.nyu.edu/emf202/public/js/dateCalculator.html
     
    emf, Jan 10, 2013
    #14
  15. emf

    emf Guest

    On 2013-01-09 20:51 Arne Vajhøj wrote:
    > On 1/9/2013 1:40 AM, emf wrote:
    >> On 2013-01-06 19:58 Arne Vajhøj wrote:
    >>> 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.

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


    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

    --
    It ain't THAT, babe! - A radical reinterpretation
    https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
     
    emf, Jan 10, 2013
    #15
  16. On 1/10/2013 7:19 AM, emf wrote:
    > On 2013-01-09 20:51 Arne Vajhøj wrote:
    >> On 1/9/2013 1:40 AM, emf wrote:
    >>> On 2013-01-06 19:58 Arne Vajhøj wrote:
    >>>> 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.

    >>
    >> 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, 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
     
    Arne Vajhøj, Jan 10, 2013
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Love

    applet vs. canvas in applet

    Rob Love, Jul 7, 2003, in forum: Java
    Replies:
    1
    Views:
    634
    Liu, Chunyen
    Jul 7, 2003
  2. webster
    Replies:
    0
    Views:
    872
    webster
    Jul 20, 2003
  3. Andrew Thompson
    Replies:
    0
    Views:
    422
    Andrew Thompson
    Aug 5, 2003
  4. Archana
    Replies:
    1
    Views:
    1,394
    Andrew Thompson
    Oct 25, 2004
  5. Chirag
    Replies:
    2
    Views:
    2,318
    Andrew Thompson
    Jan 9, 2005
Loading...

Share This Page