Results 1 to 4 of 4
- 08-03-2010, 03:41 AM #1
Basic Java applet error, cant figure it out!
the applet is at http://primecode.co.uk/
page source is
i have uploaded two files to the root directory alongside the index.html page, these files are named fun.class and javaapplication28.jar, however when i run the applet i get this errorPHP Code:<html> <body> <applet code = 'fun.class' archive = 'javaapplication28.jar', width = 300, height = 300 /> </body> </html>
java.lang.NoClassDefFoundError: fun (wrong name: javaapplication28/fun)
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(Unknow n Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: fun (wrong name: javaapplication28/fun)
i have uploaded a previous applet with the same html markup so im not sure whats wrong, however whats different between this new applet thats ive uploaded and the old one is that this applet is in a package whilst my old one wasnt. the package is called 'javaapplication28'. now i noticed that when i compiled the applet into a jar file it named it JavaApplication28 and so i thought this was given the error because it was a different case but when i changed it to lower case on the webserver i still get same error.
below is the source code to my class file.
thanks for taken the time to look.
PHP Code:package javaapplication28; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class fun extends JApplet { JButton jb; JTextField jt; JPanel jp; String text = "hello"; @Override public void init() { setLayout(new BorderLayout()); jp = new JPanel(); jp.setLayout(new FlowLayout()); jt = new JTextField(" "); getContentPane().add(BorderLayout.NORTH,jt); getContentPane().add(BorderLayout.CENTER,jp); jb = new JButton("Change text"); jp.add(jb); jb.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){ text = jt.getText(); repaint(); }}); } @Override public void paint(Graphics g){ super.paintComponents(g); g.drawString(text, 50, 50); } }Teaching myself java so that i can eventually join the industry! Started in June 2010
- 08-03-2010, 04:54 AM #2
in this case, the problem might be because you have created the fun class inside the package "javaapplication28", so either reference the class within a folder (e.g. package) inside the classes location (or in the jar file) in your website, such as by changing the applet tag to bejava.lang.NoClassDefFoundError: fun (wrong name: javaapplication28/fun)
or, change (remove) the package in your java file and recompile it so the class lives in the default (top-level) package.Java Code:<html> <body> <applet code = 'javaapplication28/fun.class' archive = 'javaapplication28.jar', width = 300, height = 300 /> </body> </html>
- 08-03-2010, 02:09 PM #3
Did you test the html/jar file from a local disk before uploading it to a server?
That would verify that the HTML and the jar were correct.
If your class is in a package, your html and jar file contents must reflect that,
The html would use: code = 'javaapplication28.fun'
The fun.class file would be in the javaapplication28 folder in the jar
- 08-03-2010, 06:25 PM #4
Similar Threads
-
need help to figure out basic java program
By shane123 in forum New To JavaReplies: 21Last Post: 12-02-2011, 04:12 AM -
i have a small error but i can't figure out what is wrong [code provided]
By blueduiker in forum New To JavaReplies: 3Last Post: 01-11-2010, 06:48 AM -
Java assignment - couple methods don't know how to figure out
By Snowboardmylife in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:52 AM -
Basic Applet
By jkswebsite in forum Java AppletsReplies: 4Last Post: 01-13-2008, 09:14 PM -
Basic graphics applet
By Godzilla in forum New To JavaReplies: 3Last Post: 08-08-2007, 09:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks