What does a never ending Java Applet loader signify? - java

Currently I am trying to embed a Java applet onto a webpage, and the only result I get is the java logo spinning and an empty loading bar.
example
I can't tell if its an error in my Java code or if I did something wrong with the HTML file.
Here is what I have for HTML.
<applet>
archive="game.jar"
code="BRANDON.GameApplet.class"
width=800
height=600
</applet>
BRANDON is the package I created with the rest of my files and GameApplet is the class which has the applet necessary methods. The game.jar is located in the same location as my HTML file, and the GameApplet class file is located in the jar within the BRANDON folder. The applet runs just fine in eclipse when told to run as an applet so I can't imagine it being a problem with the Java code.
My suspension is that it is a problem with file placement but every variation I try comes up with similar results. Anyone know what the mysterious loader means, and what I am doing to cause it?
Thanks to anyone who might answer.
EDIT: Just enabled the developer console and the only output it gives me is:
APPLET tag missing CODE parameter.
I don't know how much this helps.

Enable the Java Console so you can see the error messages and take appropriate action.
edit: You need it inside the applet tag
<apple code="..." ...>
now it is just some text inside the tag.

My suspicion is that your class files are simply not being found, though I don't have enough info to know for sure. Some thoughts:
double-check the file structure inside of game.jar. e.g. GameApplet.class should appear in the BRANDON/GameApplet.class folder relative to the root of your jar file.
check that your folder names and class names are correct
check that when you jar'd your applet, you didn't forget to include class files. I have jar'd all of my source files before, forgetting to compile them before creating the jar

Related

Passing from java to HTML

I have i problem, I made a program in java using eclipse compilator, the thing is that It has two packages and in each package there are 3 classes i have tried to insert this code in a html file useing the applet tag but the problem is that it doesnt works, i dont know how to do it, and its quite important
I have tried using applet tags and tried the .jar I found something like this
<applet codebase ="." code="zuve.ZuveApplet.class"
archive=".jar,1.jar"
height="1000" width="1000"/>
I recomend you do a short tutorial on Applets:
http://java.about.com/od/webapplications/ss/firstapplet_3.htm
It is quite easy and you may made a misstake at one of those important points:
Compile your source: This includes a.) having your .java files beeing transformed to .class files and b.) packaging everything into a .jar file (you can make a .zip and rename it to .jar by hand).
Link your applet: This is done like described here: http://docs.oracle.com/javase/tutorial/uiswing/components/applet.html. You want to have both of your different packages packed in ONE .jar and have that single jar defined as argument 'archive' while your argument Code has to point to your applet class (e.g. the one extending from either Applet or JApplet or something like that).
Make sure that paths are set properly, easiest way would be to have everything (the .html with the applet tag and the .jar with your applet code inside) inside the same folder.

Can't fix NoClassDefFound error in Java

I build project in eclipse - swing applet and now I'm trying to run it in a browser.
I have 3 packages, let's say they are called: "pkgApplet", "pkgFirst", "pkgSecond" with .class files. In pkgApplet I have class "main" with method main(). No matter what I do, I can't run this applet in browser. Currently my html code looks like this
<applet code="bin/pkgApplet/main" height="1000" width="1000"/>
Browser gives this error every time no matter how I modify applet tag:
NoClassDefFoundError with message bin/pkgApplet/main(wrong name: applet/main)
I tried using codebase attribute, packing applet into .jar file and using archive attribute, but nothing seems to work. Do you have any idea what am I doing wrong?
Your applet format should be:
<applet codebase="bin" code="pkgApplet.main" height="1000" width="1000"></applet>
bin is the default target directory (for Eclipse) so will require the codebase attribute as shown above. For this to work, your HTML file needs to be located in your project directory.
Note classes in Java start with uppercase, while package names are lowercase. Also its helpful to name classes describing what they do. You could have instead:
<applet codebase="bin" code="pkgapplet.MyMainApplet" height="1000" width="1000"></applet>
Do you realize that nothing in main will be called by your applet client? Any startup functionality should be placed in the init method.

Java: Applet criteria

So I'm having a tough time trying to understand the criteria that I need to follow in order for my Java program to be able to be embedded in HTML. Do I just have to extend my main class to the Applet class, or is there more that I have to do? Also, in every Applet example I've seen, it shows the code embedding a .class file, like so:
<Applet Code="MyApplet.class" width=200 Height=100>
</Applet>
Do I need to have all the .class files stored in a folder seperately, or does it just read the .class file specified from the compiled .jar?? I'm fairly lost here, if someone could clarify it would be much appreciated. Thanks
Definitely you can specify the jar class of jar file. be sure that you have put the jar in your class path and specify the full qualified path of the class file
refer for how to create applet

find file location in java.io.FileNotFoundException

I have this Java application and I'm using an external Jar and one of the functions is throwing a java.io.FileNotFoundException. I have the file that it's looking for but I have no idea where I'm supposed to put it. Is there any program I can use that can give me the location of the path that it's trying to look at? Thanks.
if you run the application in a debugger, most debuggers allow you to break when an exception is thrown. you could then inspect the local state of the application to determine the relevant path.
you should also probably report this as an enhncement request to the original library author (to include the file name in the thrown exception).
Don't you have to the .class file of the Java class containing that method.If yes, decompile it to view the source code. This is one such decompiler
Also, try to look for any config file like a property file that may have the path information.
You can find the current working directory from System.getProperty("user.dir") and do some hit-trial by placing the file there.
If the exception stack does not give you a hint on where it is looking for the file, and placing it in common places e.g.
in user directory
home directory
current directory etc
does not work, I guess you can decompile the jar and see where it is looking for the file
Well, I doubt it is hardcoded so this will probably not show you exactly where it is looking...but you may want to decompile the class using JAD. This may clue you in on where it is looking.

Embedding a java applet in Wordpress

I have an applet that works alright on this page. It just references the .class file. (unfortunately, I have lost the source, and the jar files.)
I want to reference it here, however it does not start. Probably because it cannot find the class file. the applet tag looks like this
<applet code="/applets/language/LanguageEngineApplet.class" width="1174" Height="402">
<embed code="/applets/language/LanguageEngineApplet.class" width="1174" height="402" type="application/x-java-applet" pluginspage="http://www.java.com/en/download/manual.jsp"/>
</applet>
I know the .class file is there, because I can link to it. So I'm stumped as to why this won't work.
I just put the applet in a page on it's own. The problem was not my Java version, it was the class name and the path and the package interacting somehow. I had to put it in a directory on its own, with the html file that referenced it in that directory.
You may want to look at the Java Deployment Toolkit
If you do decide to embed a Java applet inside WordPress and not outside, I just released a new plugin that easily allows you to do that. It uses shortcodes.
http://huyz.us/2011/the-easiest-way-to-embed-java-in-wordpress/
Hmmm, maybe I have to support uploading *.class files in your case. Let me know, if you need that.

Categories