Directory is like so:
test.html
blah
hmmm
Inside "blah" we have all the applet files, including blahBlah.class. Inside "hmmm" are a few more more class files that were taken from a library or something, they are used by the project also.
I write in test.html...
<applet name="blah" code="/blahBlah.class" codebase="blah"></applet>
(along with every other variation I could think of)
Farthest I've gotten is:
java.lang.NoClassDefFoundError: blahBlah (wrong name: blah/blahBlah)
Now inside blahBlah.java, we have:
package blah;
I'm not sure if it's related.
Also wondering if it may be necessary to place the project in a jar file and set the archive attribute of the applet?
The real files are not blah and blahBlah, but I've replaced the names faithfully.
java.lang.NoClassDefFoundError: blahBlah (wrong name: blah/blahBlah)
This basically means that it's been executed as
java blahBlah
instead of
java blah.blahBlah
In other words, your code attribtue is wrong. It has to be
<applet name="blah" code="blah/blahBlah.class" />
or just by FQN (see also Andrew's comment)
<applet name="blah" code="blah.blahBlah" />
The codebase defaults to the current folder, which is fine in this case, so it's removed. An alternative is to put it in another folder, such as /applet or something. You should at least not use a package folder as code base, but instead the package root.
Related
I have this JApplet jar and tried to open it on the web.
But I keep getting this error
java.lang.NoClassDefFoundError: org/json/JSONException
I've searched the answers here and tried them, but didn't work.
Even if I already added the java-json.jar in my build path of the project.
this is my html code for running my jar file on the web
<applet archive="PDDS.jar" code="MainFrame.class" width="960" height="540">
I have two classes inside PDDS.jar, the JApplet class is the MainFrame.class, the other one is a class for connecting to the sqlite database.
Even if I already added the java-json.jar in my build path of the project.
The build path of a project has nothing to do with the runtime class path, which is set in the applet element.
So..
<applet archive="PDDS.jar" code="MainFrame.class" width="960" height="540">
Should be more like..
<applet archive="PDDS.jar java-json.jar" code="MainFrame.class" width="960" height="540">
Note also that the code attribute should best be the fully qualified name of the applet class, not the file name, so it would look like:
<applet archive="PDDS.jar java-json.jar" code="MainFrame" width="960" height="540">
There is a class a.b.c.Hello of which I would just get the Hello.class file delivered. I would like to run using something like:
java Hello
//or
java a.b.c.Hello
This leads me to a NoClassDefFoundError. Normally I'd have the a/b/c dirs with the class insdie and I'd add them to the -classpath option, but:
Is there a way of running a class in a package like this without having to put it inside a/b/c to match the package name?
All solutions I've found state the directory structure has to match the package naming, but I'd like to run the .class file directly from the folder where it is without recreating the folder structure
Is there a way of running a class in a package like this without having to put it inside a/b/c to match the package name?
Yes: By using a jar. Put the .class file in the jar (with the correct path), and then:
java -cp TheJarFile.jar a.b.c.Hello
This is, of course, very much like putting it in an a/b/c directory; it's just that the directory is in the jar, not the file system.
The packages do not just structure your classes (in folders), they also create a namespace. While the simple class name is Hello, the real class name is a.b.c.Hello.
That's because class names might repeat frequently (in different libs, f.e), but must be addressable on the other hand. For example: 'User', 'Logger', 'List', 'Date'.
Its not recommended, but you can put your class in the default package, too. Just remove the 'package ...' line.
So I'm running into a problem here getting an applet to run. The .class file is in another directory and I've learned that you can use the codebase attribute to point to where the file is. Here is my calling code.
<applet codebase="/Cartographer/bin" code="CartographerApplet.class" width="300" height="150"></applet>
Now the .class file i'm looking for is in a package I've deemed Cartographer.
My question is, is there something I'm missing? Or is my code completely wrong? I have a hunch that I'm not doing the codebase part correctly because I don't really know how to provide a shortened path without giving the whole C:\ect\ect\ect path.
Edit: The root directory has the folder Cartographer in it which houses the java project for creating the app. So the path I have is what points to the .class file I need. I've tried using the code attribute with and without the Cartographer package attached to the beginning and I keep getting a class not found exception.
I'm confused on how to correctly specify a applet's code attribute in a webpage. I have an applet with the absolute path of
~/workspace/myProject/bin/A/B/C/app.class
and my HTML is under myProject. app.class has the package declaration of
package A.B.C
How do I specify that the page should first look in bin and then A,B,C? If I stick the page in /bin, I can use
code = "A/B/C/app.class"
and it works fine, but putting it in myProject and trying
code = "bin/A/B/C/app.class"
doesn't work. I think its because of that package declaration but I don't know how to fix it; i can't change the package declaration. Do I need to use . in someway? I've seen that before and used it in another solution but trying with various combinations of . instead of / doesn't work either. As a side question, could someone explain what the difference between . and / is? This just says its used for delineating file type
You would use dots instead of the slashes and specify the CODEBASE accordingly
<applet code="A.B.C.app.class" codebase="bin" width="300" height="200">
</applet>
Can anyone help me out. I've written a program that controls the heating system in an imaginery house, an applet actually. it runs fine in netbeans but i cant get it to run as an applet in a browser, can anyone help me out please, I linked to a zip folder of all my code...
http://dl.dropbox.com/u/47863/Heating%20System.zip
http://alcaeos.com/applet/classes/MyHomeHeating.class -> 404.
Or to put that another way.
The applet element is telling the JRE to look for the class at the URL mentioned above.
The class is not at that location. (Neither is it in the same directory as the HTML.)
Where is the class file?
BTW: Typical bloody Netbeans generated code (/HTML). When what it generates is not invalid, it is redundant.
code="MyHomeHeating.class" The code attribute should not include .class.
<HR WIDTH="100%"> An HR element normally spans the entire width of the page.
You need to compile your applet into .class files (not .java files like you have in the ZIP; those are source code) and embed it into an HTML page. You can use the tag in HTML to do these; read more here: http://www.echoecho.com/applets01.htm