Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Main Class Not Found Problem

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Main Class Not Found Problem

    Hello. I haven't done much Java programming for a few years and have recently installed the Java 6 SDK. I cant seem to figure out how to fix this problem though. It works fine under Java 5. Here is the error.
    C:\Program Files\Java\jdk1.6.0_16\bin>java "z:\java_stuff\SwingExample.class"
    Exception in thread "main" java.lang.NoClassDefFoundError: z:\java_stuff\SwingEx
    ample/class
    Caused by: java.lang.ClassNotFoundException: z:\java_stuff\SwingExample.class
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: z:\java_stuff\SwingExample.class.  Program will e
    xit.

    Here is the actual Java code. Just a simple JFrame example.
    import java.awt.*; 
    import javax.swing.*;
     
    /**
     * Basic Swing example.
     */
    public class SwingExample {
        public static void main(String[] args) {
            // Create a JFrame, which is a Window with "decorations", 
            // i.e. title, border and close-button
            JFrame f = new JFrame("Swing Example Window");
     
            // Set a simple Layout Manager that arranges the Components
            f.setLayout(new FlowLayout());
     
            // Add a label
            f.add(new JLabel("Hello world!"));
     
            // "Pack" the window, making it "just big enough".
            f.pack();
     
            // Set the default close operation for the window, 
            // or else the program won't exit when clicking close button
            f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
     
            // Set the visibility as true, thereby displaying it
            f.setVisible(true);
        }
    }

    Any insight would be greatly appreciated. Thank you.

    Edit: Forgot to mention but it compiles just fine and the class and filename match.

    Edit: Finally found the problem.
    Last edited by shadow; September 28th, 2009 at 08:02 PM.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Main Class Not Found Problem

    Please mark as solved

    // Json

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Main Class Not Found Problem

    Hello shadow,

    Welcome to the Java Programming Forums.

    What was the solution?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Main Class Not Found Problem

    The classpath needed to be set. It's been so long since I've worked on anything non-PHP I forgot to set the environment variable. Now that I think of it, I believe I might have had my files on the same drive partition as java before so that is probably why it wasn't an issue before.

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  2. application id not found
    By pradeepsetty in forum Java IDEs
    Replies: 3
    Last Post: June 2nd, 2010, 02:37 AM
  3. could not find the main class
    By Tisofa in forum Object Oriented Programming
    Replies: 1
    Last Post: September 27th, 2009, 02:58 AM
  4. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM
  5. Replies: 9
    Last Post: June 27th, 2009, 04:05 PM