Page 1 of 3 123 LastLast
Results 1 to 20 of 59
  1. #1
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default Applet notloaded

    I've coded up a little BMI Calculator in NetBeans 6.8 using a JApplet Form.

    BMIApplet.java

    Java Code:
    package bmi;
    
    
    public class BMIApplet extends javax.swing.JApplet {
    
        /** Initializes the applet BMIApplet */
        public void init() {
            try {
                java.awt.EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        /** This method is called from within the init() method to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            lblWeight = new javax.swing.JLabel();
            lblHeight = new javax.swing.JLabel();
            lblBMI = new javax.swing.JLabel();
            txtWeight = new javax.swing.JTextField();
            txtHeight = new javax.swing.JTextField();
            txtBMI = new javax.swing.JTextField();
            btnCalc = new javax.swing.JButton();
    
            lblWeight.setText("Weight (KG)");
    
            lblHeight.setText("Height (M)");
    
            lblBMI.setText("BMI");
    
            txtBMI.setEditable(false);
    
            btnCalc.setText("Calculate");
            btnCalc.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnCalcActionPerformed(evt);
                }
            });
    
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(lblBMI)
                            .add(14, 14, 14)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(btnCalc)
                                .add(txtBMI, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(lblHeight)
                                .add(lblWeight))
                            .add(7, 7, 7)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(txtWeight, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                                .add(txtHeight, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(txtWeight, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(lblWeight))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(txtHeight, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(lblHeight))
                    .add(12, 12, 12)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(txtBMI, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(lblBMI))
                    .add(18, 18, 18)
                    .add(btnCalc)
                    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
        }// </editor-fold>                        
    
        private void btnCalcActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // Get weight from text field
            double dWeight = Double.parseDouble(txtWeight.getText());
            // Get height from text field
            double dHeight = Double.parseDouble(txtHeight.getText());
            // Calculate BMI
            double dBMI = dWeight / (dHeight * dHeight);
            // Display result in text field
            String sResult = "";
    
            if (dBMI > 25) { sResult = "Overweight"; }
            else if (dBMI < 18.5) { sResult = "Underweight"; }
            else { sResult = "Normal Weight"; }
    
            txtBMI.setText(sResult);
        }                                       
    
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton btnCalc;
        private javax.swing.JLabel lblBMI;
        private javax.swing.JLabel lblHeight;
        private javax.swing.JLabel lblWeight;
        private javax.swing.JTextField txtBMI;
        private javax.swing.JTextField txtHeight;
        private javax.swing.JTextField txtWeight;
        // End of variables declaration                   
    
    }
    I can run this and it works fine on my system. The next step is to embed it into a Web Application and a JSP page. So, I start a new project, I import the BMI project/JAR file. The JAR file is now in the same folder as the JSP page.

    index.jsp

    Java Code:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hello World!</h1>
            <applet code="bmi.BMIApplet" archive="BMI.jar" height="300" width="300"/>
        </body>
    </html>
    I'm not sure if the code line is meant to be:

    Java Code:
    code="bmi.BMIApplet.class"
    but either way, I get the same problem.

    The problem is, when I run the web application, the page just shows a box saying "Error. Click for details" and when clicked it just says the applet failed to run. At the bottom of the page it says "Applet bmi.BMIApplet notloaded".


    Can anyone offer any advice here?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Are you able to run the applet locally by having the html file and the jar file in the same folder?

    Are there any error messages in the browser's Java Console?

  3. #3
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are you able to run the applet locally by having the html file and the jar file in the same folder?

    Are there any error messages in the browser's Java Console?
    I'm using a JSP file which is in the same folder as the jar file.

    No errors that I can see.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    How are the files getting to the browser? Are they directly read by the browser (your browser reads .jsp files as html) or is there a server involved? You enter an IP address in a browser and it goes to the server for the files.

    What's in the browser's java console?

  5. #5
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    I haven't played about with java for over a year so sorry if I seem a bit slow.

    To get it running in the browser I just run the web application from NetBeans which then opens up the browser loading the jsp page using the URL "http://localhost:8080/Portfolio/"

    Glassfish V3 is up and running.

    Java Console displays:

    Java Code:
    Java Plug-in 1.6.0_17
    Using JRE version 1.6.0_17-b04-248-10M3025 Java HotSpot(TM) Client VM
    User home directory = /Users/Scott
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    p:   reload proxy configuration
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Sorry I don't know Netbeans or Glassfish.

    Does it work if you put an html file and the jar file in the same folder and open the html file with a browser?
    What browser are you using?

    I get the following in the Java console when the browser can't find the class file because of a missing jar file:

    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner

    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

    load: class AppletReader not found.
    java.lang.ClassNotFoundException: AppletReader
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: D:\www\Testing\AppletReader.class (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
    Exception: java.lang.ClassNotFoundException: AppletReader

  7. #7
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Nope, still does exactly the same if I use a HTML file in the same folder.

    I'm using FireFox but the same problem occurs in Safari too.


    I don't see how it can't find the jar file if its in the same folder. I presumed it must be something to do with the way I am 'calling' it in the jsp/html file but I don't see what i've done wrong.


    Any idea why my console is just blank? I am on an iMac but that shouldn't cause this problem.
    Last edited by Hodson; 05-16-2010 at 12:09 PM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Sorry, I don't know about using an iMac. I have only Windows experience.
    I don't understand how you are testing the app with files in a folder. Could you show the names of the files?

    If you have an .html file and a jar file in the same folder and open the .html file with a browser, the browser should find the jar file. Then it becomes a question of if the class files have the correct path in the jar file. Can you look in the jar file (say with WinZip) and
    confirm that the files have the correct path? IE the BMIApplet class is in the bmi folder.

    Also do your browsers support the java plugin needed for applets?

  9. #9
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Here's the folders & files:



    I am using a jsp rather than a html file but I have also used a html file (placed in the same directory) and get exactly the same results.

    I have downloaded the jar file, from http://localhost:8080/Portfolio/BMI.jar, and extracted it and it does contain the BMIApplet.class file:



    And yes, the browser does work with applets as I have ran them from other sites.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    When I open the above shown html in Firefox I get the same display in the browser as you do. I do not have a jar file. When I click for details I get a dialog window as you do. My dialog window has a "Details" button that if clicked opens the Java Console window which has this:

    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner

    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

    load: class bmi.BMIApplet not found.
    java.lang.ClassNotFoundException: bmi.BMIApplet
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: D:\JavaDevelopment\Testing\ForumQuestions3\bmi\BMI Applet.class (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...onnect(Unknown Source)
    at sun.net.http://www.protocol.file.FileURLConn...Stream(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
    Exception: java.lang.ClassNotFoundException: bmi.BMIApplet

    No idea what else to try. Just double check everything is correctly named/spelled and in the right place.

  11. #11
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    I noticed that in the error message you see, you have the path of:

    D:\JavaDevelopment\Testing\ForumQuestions3\bmi\BMI Applet.class


    It should be BMIApplet.class


    I have looked at my code so much and can't see anything wrong but I will take another look.

  12. #12
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    I just created another very simple JApplet which consisted of just a button and I got exactly the same problem.

    I really don't understand what is causing this problem.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Here's the html I used for the above test.
    Java Code:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hello World!</h1>
            <applet code="bmi.BMIApplet" archive="BMI.jar" height="300" width="300"/>
        </body>
    </html>
    The .html file was in the folder: D:\JavaDevelopment\Testing\ForumQuestions3\

    Do you have any html and jar files on your computer that do work? If so look at the html and the contents of the jar file and compare that with the one that is failing.


    Do you get a "Details" button on the error dialog display mentioned above? What happens when you click it?

  14. #14
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    No, I don't currently have any working ones on this computer. I may see if I can download some examples from sites and get them working.

    I load the page and see this:



    I click it and see this:



    I click details and get this:


  15. #15
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    I'm trying to download some example applets to run but none of them seem to contain a jar file, they all just call the class file.

    They work fine though when I run the html file.

  16. #16
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    emm...

    load: class bmi.BMIApplet not found.
    java.lang.ClassNotFoundException: bmi.BMIApplet
    Is the class currently in the jar ?

    So you say that you have moved it from your IDE or something to another IDE? Is that you mean?
    Sorry but I dearly think you should deploy your applet etc before running :) to run applet with jsp they both should have all the same paths.
    As for tomcat:
    You should place your applet and JSP in webapp project folder correctly to get them work...
    something like a
    |webapp
    ||myappletproject (folder/war)
    |||WEB-INF (folder)
    ||||myClients (folder)
    |||||*.jar *.jsp etc

    It is all depends of your web.xml project configuration params...

    you know I mean? Just deploy it and tell us the result...
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  17. #17
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Yes, the class in in the jar file.

    I wrote the BMI calculator applet in NetBeans in its own project. It ran fine when deployed in NetBeans. I then wanted to have it deployed via a JSP on the internet so I started a new web project and packaged the jar file into this project. This is where the problem lies, when I deploy and run the web project, the JSP loads but the applet doesn't.

    Both files do have the same path/are in the same folder.

    The web.xml file could be the problem as the project doesn't seem to have one. I will have to look into what needs to be written in this web.xml file.

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    the class in in the jar file.
    Does it have the correct path: bmi/BMIApplet.class It must be in folder bmi

    The .xml file is not used by a browser when looking for classes used in the <APPLET tag

  19. #19
    Hodson is offline Member
    Join Date
    May 2010
    Posts
    26
    Rep Power
    0

    Default

    Yeah:


  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Seems like it should work. If the html file with the archive=BMI.jar and the BMI.jar file are in the same directory and you open the html file a browser, the browser should read the BMI.jar file and find the bmi.BMIApplet.class file.

    So what's wrong? Check spellings. Case is important

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 09-29-2009, 03:33 PM
  2. Applet with RS-232
    By j_jpg in forum Java Applets
    Replies: 0
    Last Post: 07-07-2009, 10:59 AM
  3. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 12:54 PM
  4. Need with an applet
    By maggie_2 in forum Java Applets
    Replies: 6
    Last Post: 09-21-2008, 08:07 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •