Results 1 to 7 of 7
  1. #1
    KM88 is offline Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    14
    Rep Power
    0

    Default confused... applet won't run.

    My applet runs fine in Eclipse, and previous applets I made work fine as well, but for some reason this one won't. Here is my code:


    package q5;

    import javax.swing.JApplet;
    import java.awt.*;

    /**
    * @author your name here
    *
    */
    public class BusinessCard extends JApplet {

    Font textFont, textFont2, textFont3;

    public void init() {
    setSize(600, 400);
    textFont = new Font("TimesNewRoman", Font.ITALIC + Font.BOLD, 40);
    textFont2 = new Font("TimesNewRoman", Font.PLAIN + Font.BOLD, 20);
    textFont3 = new Font("TimesNewRoman", Font.PLAIN, 14);

    }

    public void paint(Graphics g) {

    int x, y; // x and y coordinates of upper left-corner of each shape
    int width, height; // width and height of each shape

    setBackground(Color.white);

    g.drawRect(50, 50, 500, 300);

    g.setColor(Color.cyan);
    g.fillRect(51, 51, 499, 79);

    g.setColor(Color.red);
    g.fillOval(400, 65, 60, 50);

    g.setColor(Color.green);
    g.fillOval(430, 65, 60, 50);

    g.setColor(Color.blue);
    g.fillOval(460, 65, 60, 50);

    g.setColor(Color.black);
    g.setFont(textFont);
    g.drawString("Sage Styling", 100, 102);
    etc...

    }
    }


    and then the HTML file is:

    <html>
    <applet code="BusinessCard.class" width=800 height=500>
    </applet>
    </html>


    this is the error I get when I try to load the applet:

    java.lang.NoClassDefFoundError: BusinessCard (wrong name: q5/BusinessCard)
    at java.lang.ClassLoader.defineClass1(Native Method)
    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 java.lang.ClassLoader.loadClass(Unknown 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: BusinessCard (wrong name: q5/BusinessCard)


    any help would be greatly appreciated :) All files are in the same folder, and when I double click the HTML file I get this error. Nothing is misspelt, I'm unsure what to do :/
    Last edited by KM88; 10-11-2009 at 06:28 PM.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    You didn't package your applet properly. The class is in a package called q5 so it's FQN is q5.BusinessCard.
    Read Sun's tutorial to find out more.

  3. #3
    KM88 is offline Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    14
    Rep Power
    0

    Default

    I changed my HTML file to

    <html>
    <applet code = 'q5.BusinessCard',
    width = 800,
    height = 500 />
    </html>

    like Sun's tutorial says to but it still can't find the BusinessCard.class. :/

    my teacher added the "package q5;" line to our program. I'm not sure what it does, but when I try to delete it my whole program doesn't work.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Did you package the classes in a jar file and specify the location of the jar file?

  5. #5
    KM88 is offline Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    14
    Rep Power
    0

    Default

    yeah I used Ant to package BusinessCard.class into bcard.jar

    I then changed my HTML to:

    <html>

    <applet code = "BusinessCard"
    archive = "bcard.jar"
    width = 800 height = 500 />

    </html>

    for the code part I've tried all sorts of combinations such as q5.BusinessCard, q5\BusinessCard, BusinessCard, with it ending in .class, etc

    still nothing has worked... :/ I've been trying to look up the info myself reading tutorials, but tbh I'm not sure what I'm doing wrong so it's kind of hard to find the info.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Don't try many different things. Just do what Sun's tutorial says. Did you put the class in a folder called q5 before creating the jar file?

  7. #7
    KM88 is offline Member
    Join Date
    Oct 2009
    Location
    Canada
    Posts
    14
    Rep Power
    0

    Default

    thank you r035198x, it works now.

    no I hadn't created a q5 folder before creating the .jar file :/

    on the Sun tutorial page you linked me they had:

    <applet code = 'appletComponentArch.DynamicTreeApplet'
    archive = 'DynamicTreeDemo.jar',
    width = 300,
    height = 300 />

    I wasn't sure what that "appletComponentArch" part of the code was. Now I see it was just the folder DynamicTreeApplet was in.

    thanks again! :)

Similar Threads

  1. Very confused Plz help!!
    By ratb0y in forum NetBeans
    Replies: 0
    Last Post: 02-14-2009, 05:34 PM
  2. Confused
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 02:00 PM
  3. confused
    By updev in forum AWT / Swing
    Replies: 6
    Last Post: 11-14-2008, 04:33 PM
  4. a lot confused
    By vineethraj in forum New To Java
    Replies: 4
    Last Post: 01-18-2008, 01:36 AM
  5. what does it mean:confused:
    By sivasayanth in forum New To Java
    Replies: 2
    Last Post: 01-12-2008, 05:52 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
  •