Results 1 to 4 of 4
  1. #1
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default Basic Java applet error, cant figure it out!

    the applet is at http://primecode.co.uk/

    page source is

    PHP Code:
    <html>
    <body>
    
    <applet code = 'fun.class' 
        archive = 'javaapplication28.jar',
        width = 300, 
        height = 300 />
    </body>
    </html>
    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 error


    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

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    java.lang.NoClassDefFoundError: fun (wrong name: javaapplication28/fun)
    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 be
    Java Code:
    <html>
    <body>
    
    <applet code = 'javaapplication28/fun.class' 
        archive = 'javaapplication28.jar',
        width = 300, 
        height = 300 />
    </body>
    </html>
    or, change (remove) the package in your java file and recompile it so the class lives in the default (top-level) package.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    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

  4. #4
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    thanks you travishein and norm for your help :)
    Teaching myself java so that i can eventually join the industry! Started in June 2010

Similar Threads

  1. need help to figure out basic java program
    By shane123 in forum New To Java
    Replies: 21
    Last Post: 12-02-2011, 04:12 AM
  2. Replies: 3
    Last Post: 01-11-2010, 06:48 AM
  3. Java assignment - couple methods don't know how to figure out
    By Snowboardmylife in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:52 AM
  4. Basic Applet
    By jkswebsite in forum Java Applets
    Replies: 4
    Last Post: 01-13-2008, 09:14 PM
  5. Basic graphics applet
    By Godzilla in forum New To Java
    Replies: 3
    Last Post: 08-08-2007, 09:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •