I went to the official JAVA forum, but either those guys there have no clue how to solve this or there's no solution to it, in which case, Java applets are useless and java should stop pimping it.

I have to say, this is the most frustrated I've been at Java in my life.

Anyways, 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.class

I realised I was running the HTML file from the src folder where the .class file isn't located, so I moved the HTML file to the bin folder where the .class file is located, 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)

Can someone please tell me what's wrong? I've been moving files from place to place and I cannot for the love of God figure out why my HTML file won't display on my browser just as every tutorial out there on the net says it should

i think removing .class would solve this issue

<applet code = "SiteTesting" width = "300" height = "75">

oClassDefFoundError: SiteTesting (wrong name: networking/SiteTesting)

Is your program in the networking package? If so you need to add the full package name to the class name: code = "networking.SiteTesting"
Then the class file would have to be in the networking folder.

A simpler solution is to remove the package statement from the code. Then there are no package path problems.

Hi, tizon, thanks for your answer. I removed the .class and I got this error:

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)

NormR1, hi, thanks for your answer. I put in "networking.SiteTesting" and I got this error:

load: class networking.SiteTesting not found.
java.lang.ClassNotFoundException: networking.SiteTesting
	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\networking\SiteTesting.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: networking.SiteTesting

When I remove the package statement from the code, eclipse marks an "X" on the file. Since my eclipse is set to build automatically, I'm assuming .class file is modified accordingly. Then I run the HTML file and I get the error I got when I made the corrections suggested by tizon.

Just as a reminder (in case this will help), my eclipse creates two paths, one for the .java file and one for the .class file. They are:

F:\Workspace\RefreshalCourse\src\networking\SiteTesting.java
F:\Workspace\RefreshalCourse\bin\networking\SiteTesting.class

The HTML file is currently in the second path where the .class file is. I've moved the .class file to the first path and put the HTML file there and the errors are still the same :(

Sorry, I don't know anything about your IDE. I find that they get in the way a lot.

You have too many variables in your testing. Simplify it>
Remove the package statement, compile the .java fle and copy the html file and the class files to a test folder and use <APPLET code=SiteTesting
what happens?


The following is another confusion:

Caused by: java.io.FileNotFoundException: F:\Workspace\RefreshalCourse\src\networking\networking\SiteTesting.class

Why is this full path shown? What code is looking for a file at that address?
Are there two folders: networking one in the other?

Ok, cheers to everyone who tried helping me out. You guys actually gave me the idea I needed to fix this problem.

Just in case anyone out there ever runs into a problem like this, here's a solution.

What you need to know is if you write your java applet without a package (if your IDE works like that) then you probably won't run across this problem.

If your IDE creates packages, like Netbeans and Eclipse, here's what you should do.

First, using netbeans is way better than eclipse in situations like this. When you create a project with netbeans, right-click on your package, select "new", "other", choose "Java" on the left-hand list and choose "JApplet" on the right-hand list, click next, and then create your applet. Once you do that, go to your project folder wherever it's located, double click to enter, and then enter the "build" folder. There Netbeans would have created a HTML file bearing the same name as your JApplet file.

For those using Eclipse, Eclipse does not create any HTML file. You have to do that on your own. The trick here is to place the HTML file in the right location, and that location CANNOT be in the same folder as the .class file. That's what I found out after fiddling around. Even in the HTML file netbeans created for you, if you open it with notpad, you'll see something similar to this:

<applet codebase="classes" code = "[packagename]/[classname].class" width = "300" height = "75">

where packagename is the name of your package, and classname is the name of your class. In your HTML file, the variable Code MUST equal "packagename/classname" (you can choose to put ".class" or not).

The value of codebase, from my understanding in solving this problem, is just another folder name. Netbeans always creates a "classes" folder, in which you will find your "packagename" folder, and then within that you'll find your class file.

So following this convention, I looked at my problem. Eclipse creates a "src" or source folder for the .java files, and a "bin" folder for the .class files.

F:\Workspace\RefreshalCourse\src\networking\SiteTesting.java
F:\Workspace\RefreshalCourse\bin\networking\SiteTesting.class

"RefreshalCourse" is the name of my project folder.

So, what I did was put my HTML file in "RefreshalCourse" folder and altered my HTML code to look like this:

<applet codebase="bin" code = "networking/SiteTesting.class" width = "300" height = "75">

I went further and put the HTML file inside the bin folder and had to alter my code to look like this:

<applet code = "networking/SiteTesting.class" width = "300" height = "75">

See the difference? Since code has to have "packagename/classname" I can't have the HTML file within the package folder, "Networking". And since the HTML file is within "bin", there's no need for a "codebase = "bin", as doing so will lead to an error.

I went even further and put the HTML file way back in "C:\Workspace" and I had to alter my code to look like this:

<applet codebase = "RefreshalCourse/bin" code = "networking/SiteTesting.class" width = "300" height = "75">

Note that "codebase" has changed here.

Anyway, that's what I found out. So, if you're in the same fix this should probably help. I know a lot of people use IDEs and packages.

Thanks, NormR1 and tizon. Appreciate the help :D

commented: Good points for other IDE users +2

Thanks for posting that. I'm sure it'll help others with IDEs figure out what is going on.

Thanks for posting that. I'm sure it'll help others with IDEs figure out what is going on.

i am noob with IDE's i use notepad and cmd for my java and thanks for posting the solution :)

Thanks a lot for the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.