Java applet won't load on browser - Java Applet Development

God, I've never been this frustrated with Java before.
Ok, I created an applet in my eclipse IDE and ran it. It works. I decided to create a HTML file so that the applet would display on my firefox browser (my browser has no problem displaying java applets. All settings are fine).
This is my HTML code:
<html>
<title>Site Selector</title>
<body>
   <applet code = "SiteTesting.class" width = "300" height = "75">
   </applet>
</body>
</html>Now, my eclipse IDE creates a "src" or source folder and a bin folder. The bin folder is where the class files are kept. The HTML file was in the src folder. When I ran it, I got this:
load: class SiteTesting.class not found.
java.lang.ClassNotFoundException: SiteTesting.class
     at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: F:\Workspace\RefreshalCourse\src\networking\SiteTesting\class.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.www.protocol.file.FileURLConnection.connect(Unknown Source)
     at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 9 more
Exception: java.lang.ClassNotFoundException: SiteTesting.classMakes sense, considering the class file isn't in the src folder. So I copied the class files into the src folder, ran the HTML file, and I got this:
java.lang.NoClassDefFoundError: SiteTesting (wrong name: networking/SiteTesting)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClassCond(Unknown Source)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: SiteTesting (wrong name: networking/SiteTesting)Huh. I took the html file and placed it in the bin folder where the class file was and I ran it and got the exact same error message above.
I'm obviously doing something wrong. So, any help in fixing this will be most appreciated. Cheers 

Your java file starts with:
package networking;Right?
If so, the fully qualified name name of your class is networking.SiteTesting.
Use this in the applet tag:
<applet code = "networking.SiteTesting" width = "300" height = "75">Suppose you have your html file in the directory zzz.
Put SiteTesting.class in zzz/networking/, like this:
zzz/whatever.html
zzz/networking/SiteTesting.class 

Thanks a lot, mate. It worked!!
Yes, networking is my package :D

Related

java.lang.NoClassDefFoundError:  (wrong name)

Hi,
I know this has been discussed a million times before, but I have read through various threads in the forum and tried the suggested solutions, but I still can't run my java applet. I use NetBeans 5.5. Under "Project properties/Run", Main Class path is set to "lottoapplet.LottoAppletUI"
Beginning of my code looks like this:
package lottoapplet;
import java.math.*;
import javax.swing.JLabel;
import javax.swing.*;
import java.text.*;
public class LottoAppletUI extends javax.swing.JFrame {
...
If I build the project and try to run the applet in a browser with the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<applet code="LottoAppletUI.class" width="641" height="431">
</applet>
</body>
</html>
I get a gray box and an "X" and the java console says the (in)famous:
java.lang.NoClassDefFoundError: LottoAppletUI (wrong name: lottoapplet/LottoAppletUI)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
If I use the command prompt, the compile works fine with the -cp parameter but applet won't run:
C:\Documents and Settings\masaxp>javac -cp "C:\Documents and Settings\masaxp\My
Documents\Java projects\LottoApplet\src\lottoapplet" "C:\Documents and Settings\
masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\LottoAppletUI.java
"
C:\Documents and Settings\masaxp>"C:\Program Files\Java\jdk1.6.0_01\bin\java.exe
" "C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\src\l
ottoapplet\LottoAppletUI"
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Documents and Sett
ings\masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\LottoAppletUI
I can run the project in the NetBeans IDE without a problem. Anyone that can decipher this and see the problem? Thanks anyway. 
Compilation looks for file names, runtime looks for class names. The full name of your class is lottoapplet.LottoAppletUI, not LottoAppletUI. 
Thanks for your reply,
when I change:
<applet code="LottoAppletUI.class" width="641" height="431">
</applet>
to:
<applet code="lottoapplet.LottoAppletUI.class" width="641" height="431">
</applet>
I get:
inl?sning: klassen lottoapplet.LottoAppletUI.class finns inte.(does not exist in english)
java.lang.ClassNotFoundException: lottoapplet.LottoAppletUI.class
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\lottoapplet\LottoAppletUI\class.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.www.protocol.file.FileURLConnection.connect(Unknown Source)
     at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
     at sun.applet.AppletClassLoader.getBytes(Unknown Source)
     at sun.applet.AppletClassLoader.access$100(Unknown Source)
     at sun.applet.AppletClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 10 more
If I change to:
<applet code="lottoapplet.LottoAppletUI" width="641" height="431">
</applet>
I get:
inl?sning: klassen lottoapplet.LottoAppletUI finns inte.(does not exist in english)
java.lang.ClassNotFoundException: lottoapplet.LottoAppletUI
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\lottoapplet\LottoAppletUI.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.www.protocol.file.FileURLConnection.connect(Unknown Source)
     at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
     at sun.applet.AppletClassLoader.getBytes(Unknown Source)
     at sun.applet.AppletClassLoader.access$100(Unknown Source)
     at sun.applet.AppletClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 10 more
why is this so difficult? Time should be spent on coding not on pathways.
Thanks,
Mattias 
Where is the LottoAppletUI.class file relative to your HTML page? 
Currently in the same folder. I have tried moving it around but it just generate errors.
Thanks. 
It should be in a directory lottoapplet relative to the HTML file. If that doesn't work, create a jar containing the LottoUIApplet inside a lottoapplet folder and run the applet from the jar. 
This is getting ridiculous, it's completely irrational. Look at this, I put index.html in this folder: C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\build\classes
and LottoAppletUI.class in ..\classes\lottoapplet
then java console says:
java.lang.ClassNotFoundException: LottoAppletUI
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\build\classes\LottoAppletUI.class (The system cannot find the file specified)
Ok, so I move the .class file one level up to \classes, but then again:
java.lang.NoClassDefFoundError: LottoAppletUI (wrong name: lottoapplet/LottoAppletUI)
If I add the jar file I still need to have the classfile declared as the applet code, right? Like this:
<applet code="LottoAppletUI" archive="LottoApplet.jar width="641" height="431">
this will yield java.lang.NoClassDefFoundError: LottoAppletUI (wrong name: lottoapplet/LottoAppletUI)
Is there another way to use the archive? Would it help switch to another IDE like Eclipse and build the project there? 
btw, the jar file that the NetBeans IDE creates and puts in the dist folder under the project folder executes without a problem if double-clicked, this jar file is also 50% larger than the jar file I created. Can I use just the jar file in a web page? 
Anyone, please help me, I'm completely stuck!
Message was edited by:
javaException 
Use the jar, put it in the same directory as your html file and change your applet tag like this:
<applet codebase="myjarfile.jar" code="lottoapplet.LottoAppletUI"> 
I reinstalled everything and moved the code to another project. Didn't help but I tried different ways to compile the java file in the command prompt and then it suddenly worked. I can now execute the class file with java.exe. However, when trying to run it as an applet the java console says:
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
     at java.security.AccessControlContext.checkPermission(Unknown Source)
     at java.security.AccessController.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkExit(Unknown Source)
     at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
     at lotto.Lotto.initComponents(Lotto.java:94)
     at lotto.Lotto.<init>(Lotto.java:20)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
     at java.lang.reflect.Constructor.newInstance(Unknown Source)
     at java.lang.Class.newInstance0(Unknown Source)
     at java.lang.Class.newInstance(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
One problem fixed and another one arise.
At Lotto.java:20 there's initComponents();
and at Lotto.java:94 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
Is it something you recognize?
Regards,
Mattias 
Applets don't have the permission to shut down that browser, do they?
Then setting your JFrame's default close operation to EXIT_ON_CLOSE is wrong. Try DISPOSE_ON_CLOSE or HIDE_ON_CLOSE.
I'm not sure because I never write applets. 
Yeah you're right, that part is fixed now. To further demonstrate my lack of java skills I now have this problem:
java.lang.ClassCastException: lotto.Lotto cannot be cast to java.applet.Applet
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
because it's not applet. Can I get to run in a browser or what should I do? It now looks like this:
public class Lotto extends javax.swing.JFrame {
Thanks,
Mattias 
Ok, it now opens up in a browser but nothing happens when I press the button. The list at the bottom of the browser says "applet lotto2.Lotto2 started", it won't take any input.
/Mattias 
nothing happens when I press the button.It sounds like your main GUI is a JFrame, not a JApplet. Have you thought about
whipping up a standalone application version of it? Would that be easier
to debug?

Loading applet for a jar within an ear

Hi,
Apologies if my question sounds ignorant, this is the first time i'm playing with applets.
I'm trying to load an applet from a JAR (applet.jar) which contains all the files specific to the applet. The applet.jar resides within an ear (application.ear) which is deployed on JBoss.
The applet related stuff is in the package com.dms.applet (which makes up the applet.jar)
My index.html resides in a war file (webapp.war), which essentially contains a bunch of servlets. Index.html is a two frame page, which tries to load the applet in one frame and a servlet in another (servlets work fine).
My <APPLET> tag for the frame in which the applet is displayed (is another html file - applet.html) looks something like this:
<html><body>
<APPLET
     code="com.dms.applet.NavigationApplet.class"
     codebase=./"
     archive="applet.jar, application.ear"
     width=200
     height=500
>
</APPLET></body></html>
however, the applet always fails to load, i get the following exception when i open the java console:
java.lang.ClassNotFoundException:
com.dms.applet.NavigationApplet.class
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
     at sun.applet.AppletClassLoader.getBytes(Unknown Source)
     at sun.applet.AppletClassLoader.access$100(Unknown Source)
     at sun.applet.AppletClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 10 more
load: class com.dms.applet.NavigationApplet.class not found.
java.lang.ClassNotFoundException:
com.dms.applet.NavigationApplet.class
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
     at sun.applet.AppletClassLoader.getBytes(Unknown Source)
     at sun.applet.AppletClassLoader.access$100(Unknown Source)
     at sun.applet.AppletClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 10 more
It seems evident that the applet class loader can't find my applet.class and hence can't load it. I guess that its something wrong with my <APPLET> tag, but can't quite seem to get my finger on it. Do i need to explicitly tell the class loader to look for it in the applet.jar which is in the applicatin.ear?
Any help would be very much appreciated.
Thanks in advance
EnterpriseJavaBones
Hi,
I managed to fix this problem. For those who mite come across the same issue in the future, this is how i did it.
I put the applets code in the war file under an applet dir. That the the index.html is in the root (of the war dir) and the applets code is in a /applet dir.
Hence the codebase simply reads, codebase="applet/"
Cheers
EnterpriseJavaBones

java.lang.NoClassDefFoundError with jar file that has the class

Hi all,
I am wondering if any guru could just give me a tip about how to go about this error. The error is appended to the end of this post. I use a jar file as the achive. I opened the jar file and found every class needed in it. For example,it has "javax/media/j3d/Canvas3D.class" in it. However I keep getting the error.
At one point, I extracted the folders and files from the jar file and put them in the folder as the applet. The applet worked for Firefox on one of my computers but not on others due to some security errors.
I am using a quite old version of JBuilder (V8), but I configured it to use the latest version of JDK. The applet runs fine in JBuilder.
Any tip will be greatly appreciated.
java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D
     at java.lang.Class.getDeclaredConstructors0(Native Method)
     at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
     at java.lang.Class.getConstructor0(Unknown Source)
     at java.lang.Class.newInstance0(Unknown Source)
     at java.lang.Class.newInstance(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
     at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Canvas3D
     at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClassInternal(Unknown Source)
     ... 8 more
Caused by: java.io.IOException: open HTTP connection failed:http://www.biyee.net/v/cie_diagrams/javax/media/j3d/Canvas3D.class
     at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
     at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 12 more
Exception: java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D

why aren't my applets working?

Hi,
I'm new to Java and don't understand why my Applets aren't working.
My page is at http://unixweb.kutztown.edu/~kosl2233/SENPRO/gallery.html
And I have successfully compiled my SoundGallery.java file, and I am positive that a SoundGallery.class file is there with it. Other Java files I have in a similar directory are working, but these say "SoundGallery.class not found"
Does anyone have any ideas of what might be wrong? Thanks for the help! 
I don't know which version of Java you use, but, mine (Java 1.4.0) catchs the following error.
Java (TM) Plug-in: Versi?n 1.4.0_03
----------------------------------------------------
----------------------------------------------------
java.lang.ClassFormatError: SoundGallery/class (Bad magic number)
     at java.lang.ClassLoader.defineClass0(Native Method)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at sun.plugin.security.PluginClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Also, you should use your tag and its values with the correct tag format
<applet code='SoundGallery.class' name='SoundGallery' height='50' width='350' VIEWASTEXT>
</applet>
Don't forget the ''s. 
bad magic number = http://www.javacoffeebreak.com/faq/faq0083.html

Applet doesnt load

java.lang.NoClassDefFoundError: MainScreen (wrong name: gui/MainScreen)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
I have a class called MainScreen which extends JApplet and is in the package "gui"
Here is the code on my website:
<applet code = "MainScreen.class" codebase = "Interpool/gui/" width="200" height="200">
</applet>
Can you please tell me what I did wrong? 
The code attribute of the applet tag should be "gui.MainScreen" and the codebase should probably be "Interpool".
The way you have it now, you're telling the JVM to look in the directory "gui" for a class with no package (i.e., the default package) which is a different thing from telling it to look for a class in the "gui" package.
Java uses directory structure to track things in its package structure, but they're not interchangeable. The package hierarchy isn't just a synonym for the filesystem hierarchy. This throws a lot of people at first.
Message was edited by:
paulcw 
I changed my code to:
<applet code = "gui.MainScreen" codebase = "Interpool" width="200" height="200">
</applet>
and got the same error
load: class gui.MainScreen not found.
java.lang.ClassNotFoundException: gui.MainScreen
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed.
     at sun.applet.AppletClassLoader.getBytes(Unknown Source)
     at sun.applet.AppletClassLoader.access$100(Unknown Source)
     at sun.applet.AppletClassLoader$1.run(Unknown Source)
     at java.security.AccessController.doPrivileged(Native Method)
     ... 10 more
this time i showed more of the error
Message was edited by:
Nether 
It looks like the same problem happened, but for a different reason.
This time, this was in the stack trace:
Caused by: java.io.IOException: open HTTP connection failed.Are you sure you were connected to the internet when you ran this?
Was the web server running both times? With the same configuration? Was it the same server?
Can you directly download the class file by typing the full path to it in the browser's URL window? (It will look like junk if your browser tried to display it, but we're just trying to see whether it can be accessed at all.)
It's worth noting that the first time you tried it, it did seem able to connect to the server and download the class. We know that because the class loader was able to figure out that the class that it downloaded had the wrong name. But this time apparently it can't even connect.
Message was edited by:
paulcw

Categories

Resources