Results 1 to 20 of 59
Thread: Applet notloaded
- 05-15-2010, 08:56 PM #1
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
Applet notloaded
I've coded up a little BMI Calculator in NetBeans 6.8 using a JApplet Form.
BMIApplet.java
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.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 }
index.jsp
I'm not sure if the code line is meant to be: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>
but either way, I get the same problem.Java Code:code="bmi.BMIApplet.class"
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?
- 05-15-2010, 11:52 PM #2
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?
- 05-16-2010, 12:02 AM #3
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
- 05-16-2010, 12:13 AM #4
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?
- 05-16-2010, 12:25 AM #5
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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> ----------------------------------------------------
- 05-16-2010, 01:43 AM #6
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
- 05-16-2010, 12:07 PM #7
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-16-2010, 05:15 PM #8
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?
- 05-16-2010, 05:30 PM #9
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-16-2010, 06:31 PM #10
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.
- 05-16-2010, 06:37 PM #11
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-16-2010, 06:49 PM #12
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-16-2010, 08:05 PM #13
Here's the html I used for the above test.
The .html file was in the folder: D:\JavaDevelopment\Testing\ForumQuestions3\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>
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?
- 05-16-2010, 08:14 PM #14
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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:
- 05-16-2010, 08:35 PM #15
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-19-2010, 05:17 AM #16
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
emm...
Is the class currently in the jar ?load: class bmi.BMIApplet not found.
java.lang.ClassNotFoundException: bmi.BMIApplet
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 :)
- 05-19-2010, 12:17 PM #17
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
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.
- 05-19-2010, 03:30 PM #18
Does it have the correct path: bmi/BMIApplet.class It must be in folder bmithe class in in the jar file.
The .xml file is not used by a browser when looking for classes used in the <APPLET tag
- 05-19-2010, 04:33 PM #19
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
Yeah:
- 05-19-2010, 05:26 PM #20
Similar Threads
-
Pass parameter from one applet to another applet in different webpages...
By anubhavranjan in forum Java AppletsReplies: 2Last Post: 09-29-2009, 03:33 PM -
Applet with RS-232
By j_jpg in forum Java AppletsReplies: 0Last Post: 07-07-2009, 10:59 AM -
Calling another applet on click of button in one applet
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 02-19-2009, 12:54 PM -
Need with an applet
By maggie_2 in forum Java AppletsReplies: 6Last Post: 09-21-2008, 08:07 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks