Results 1 to 6 of 6

Thread: swing

  1. #1
    mnatalka is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default swing

    Hi everyone,

    Im to create an application for my collage and i need to be able to use the swing package.

    Ive got no problem compiling and runing simple application but when i want to run the example from the sun page for the HelloWorldSwing.java code

    its giving me an error that i cant make sense of:

    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing
    i have no problem compiling this source code, i vae also set up the path variable :(

    Can someone plz tell me what am i doing wrong?

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Case sensitive...

    Make sure that when you run the example code, you are typing the name of the program EXACTLY the way the class name is defined.
    For example:
    class name = HelloWorldSwing
    java helloWorld Swing = NoClassDefFoundError nastygram

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you show the class definition here on that example you have workout? Basically Java is case sensitive, that can be directed to the same error.

  4. #4
    mnatalka is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    Thank u for all your answers,

    i checked the spelling and that doesnt seem to be a problem.
    I've deleted the first line saying "package start;" and it's working fine without it.
    Would u maybe know why it could be?

    //package start; - that is my problem :P

    import javax.swing.*;

    public class HelloWorldSwing {

    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("HelloWorldSwing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    //Add the ubiquitous "Hello World" label.
    JLabel label = new JLabel("Hello World");
    frame.getContentPane().add(label);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }
    }

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default

    That's what comes of not going through the Tutorials in the proper order. If you'd done that, you would have covered this tutorial before you reached the Swing one.
    Lesson: Packages (The Java™ Tutorials > Learning the Java Language)

    db

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, you miss the first half there. :) In simple words package means the location that source file is located. Keep in mind, that's a rough idea. You must read that db's link soon.

Similar Threads

  1. MVC and swing
    By jurka in forum AWT / Swing
    Replies: 1
    Last Post: 09-15-2008, 01:32 PM
  2. What is next to Swing
    By javaplus in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2008, 10:16 PM
  3. AWT or Swing
    By bugger in forum AWT / Swing
    Replies: 4
    Last Post: 11-22-2007, 09:44 AM
  4. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM
  5. swing?? why use it
    By javaforme44a in forum AWT / Swing
    Replies: 3
    Last Post: 07-18-2007, 07:51 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
  •