Error in running applet in appletviewer: NoClassDefFoundError - java

I just ran into trouble in applet execution in webpage:
An error dialog popped up:
calculator is my class name and Exercise4 is the folder that contains it. I am sure that the html file and the calculator.class are in the same folder named Exercise4. What is happening in here?

I am sure that the html file and the calculator.class are in the same folder named Exercise4.
That would be a problem. The HTML needs to be at the root, not inside the 'package' directory.

Related

System.getProperty("user.dir") with Eclipse IDE

I've been blasting through the Java Swing tutorials on zetcode.com
I've made it all the way to Basic Swing Components II, the JTextPane component.
In this example, an HTML document is loaded into memory and placed into the textpane.
In order to find the file, zetcode.com uses:
String cd = System.getProperty("user.dir") + "/";
textPane.setPage("File:///" + cd + "test.html");
My IDE of choice is Eclipse Kepler.
I have written the code for this example's class and created the HTML document exactly as zetcode.com has shown on the page. I have placed the HTML file in the same source folder and package as the class which uses it.
But when I run the code, I hear a Windows system error sound and the JFrame pops up without any text inside the textpane.
EDIT 01:
I've named the package "com/zetcode/swingtutorial/basiccomponents/".
I've tried using getClass.getResource("/com/zetcode/swingtutorial/basiccomponents/test.html")
and I figure I must have typed this correctly because I do not get an IOException.
EDIT 02:
Here's another interesting thing:
In zetcode's system, they've used "File:///", which caused Windows to play an error sound.
But when I tried "File://", no error sound plays. D'you think that was just a typo on their part?
Either way, my html doc still isn't displayed on the pane. :S
Do you know what I could be doing wrong?
Many thanks for your help!
Try this:
textPane.setPage(YourClass.class.getResource("test.html"));
If its in package
textPane.setPage(YourClass.class.getResource("/packagename/test.html"));
System.getProperty("user.dir");
Gives you the root context location or the project location folder or you can say the current directory when JVM was started
Accordingly give the path or alternately
Try loading this way
String pathOfHtmlFile = Thread.currentThread().getContextClassLoader()
.getResource("yourHtmlFile").getPath();
textPane.setPage(pathOfHtmlFile);
provided the file is in the classpath.
System.getProperty("user.dir")
Returns the "working folder" from which the application was launched. In Eclipse I believe the working directory is the top level project folder (not in src) or it's in the folder that contains the compiled .class files. Try copying the file to those folders and see when it works.

Java HTML Web Scan

http://asprise.com/product/jia/html_javascript_scan_from_scanners.php
Need to use this and scan the document. Downloaded the program and run this code, it always says the error classNotfoundException: com.asprise.jia.ui.JiaApplet
I Placed the .java file in this structure
root folder
-Applet.html
-com
--asprise
---jia
----ui
-----JiaApplet.java
Please help me on this

Error called"NoClassDEFFoundError "comes when running a applet

Hey guys i have a problem that has been wasting my times for hours which is that i get an error saying "NoClassDEFFoundError Wrong name(bigFish/BigFish)" when i try to run my html file which include a class and that contains a applet. bigFish is my project name and package name. BigFish is my class name of the class which contains the applet. and i have located my html file called BigFish in where the BigFish class file is located. how to do this. this comes in firefox. and i can't shift to chrome. its not working since month a back(doesn't even open). how can i see my applet run on web?
..i have located my html file called BigFish in where the BigFish class file is located.
That probably won't work. A loose class file in the bigFish package needs to be in a similarly named directory of the server. So, assuming the HTML is in directory www on the server, the structure should look something like this:
www directory
bigFish directory
BigFish.class
BigFish.html

Applet on Website seems to hate Packages

So I made an Applet (not JApplet) and proceeded to upload it to my website. I put all of my .class files into a package, exported the project from eclipse to a .jar, and uploaded that to the public_html folder of my website.
In my HTML code, I put
<applet ARCHIVE="BallShooter.jar" CODE="BallShooter" width=500 height=500> </applet>
However, it seems that I kept on getting the error "ClassNotFoundException"
If I reupload the .jar WITHOUT the package, it worked fine. Could somebody please explain to me how to fix this?
For those who are wondering, this is the structure of the things in the website
/public_html/myAppletJar/myPackage/a.class
/public_html/myAppletJar/myPackage/b.class
/public_html/myAppletJar/a.png
/public_html/myAppletJar/b.png
Check all these points:
if the applet class is BallShooter, and is in the package kikiotsuka, then its source code must start with the line package kikiotsuka;. The full name of the class is thus kikiotsuka.BallShooter.
in the jar file, you should thus have a directory named kikiotsuka at the root, and this directory must contain a file named BallShooter.class
since the name of the class is kikiotsuka.BallShooter, that's what the code attribute of the applet HTML element must contain: code="kikiotsuka.BallShooter" width=...

Java applet error

I am doing a project on applets. I designed the applet using netbeans. After building the project in netbeans, I took the directory "classes" and a .html file from the "build" directory and moved it to another new directory. This .html file includes the applet. The .html file displays the applet correctly, when it is viewed from my desktop.
I uploaded the "classes" folder and the .html file to my free server (host4ufree.com) using FileZilla. If I try to view the webpage online, I get the following error instead of the applet getting displayed:
java.lang.ClassFormatError: Extra bytes at the end of class file
I am using JDk 1.6.0 update 18, and uploaded the file using FileZilla both ASCII and binary format manner. Yet, I am not able to solve the error problem. Does anybody know the solution to this? Is there something wrong in the manner in which I'm trying to add the applet to my webpage?
The question is quite unclear :S Anyway...
I uploaded the "classes" folder and the .html file to my free server
(host4ufree.com) using FileZilla.
If your applet contains more that one class I do not recommend upload the project classes folder itself but wrap your applet classes to jar file before delpoying it.
Report if that helped

Categories