Results 1 to 6 of 6
  1. #1
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default NoClassDefFoundError - Cannot find main class

    Good morning,

    I seem to have solved the first problem with compiling the ArrayListDemo.java file from the Command Prompt. No my simple problem is that I cannot run the ArrayListDemo.java file from the Command Prompt.
    This file contains the main method.

    Is there any reason as to why this is happening? How can I solve this problem?
    Attached Thumbnails Attached Thumbnails NoClassDefFoundError - Cannot find main class-running-inside-classes-folder.jpg   NoClassDefFoundError - Cannot find main class-running-inside-utilities-folder.jpg  
    Attached Files Attached Files

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default

    Javac (the compiler) compiles .java source files and produces a corresponding .class file. Java (the virtual machine) runs classes; the classes are normally stored in .class files so you should run your compiled code as:

    Java Code:
    java MyClass
    while you had to compile the source code file as:

    Java Code:
    javac MyClass.java
    kind regards,

    Jos

  3. #3
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Good Morning JosAH,

    Yes,

    I have been doing that. If you take a look at my Command Prompt screenshoots, I have compiled the files with javac and that worked fine. When I try to run the file using java it does not work. It states that it cannot find the main method.

    Take a look at the screenshots and files. Could it be my configuration of my jdk or jre? Could something on my machine be interferring with it?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by littleone View Post
    Good Morning JosAH,

    Yes,

    I have been doing that. If you take a look at my Command Prompt screenshoots, I have compiled the files with javac and that worked fine. When I try to run the file using java it does not work. It states that it cannot find the main method.

    Take a look at the screenshots and files. Could it be my configuration of my jdk or jre? Could something on my machine be interferring with it?
    Good afternoon; you are trying to run your source file (the .java file); you should run the compiled .class file without the extension. Reread my previous reply.

    kind regards,

    Jos

  5. #5
    littleone is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Have mercy on me. I totally did not even realized that I overlooked that. That surely did the trick. I guess I had been fooling around with this so long, that I did not realize I was using the .java. I trust me, I know better than that. I got hung up trying to solve the compiling issue, that I mistakenly insert the .java after the file name.

    Thanks for your help. I want to mark this as solved, how do I go about doing that?

    Best regards,

    littleone

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by littleone View Post
    Have mercy on me. I totally did not even realized that I overlooked that. That surely did the trick. I guess I had been fooling around with this so long, that I did not realize I was using the .java. I trust me, I know better than that. I got hung up trying to solve the compiling issue, that I mistakenly insert the .java after the file name.

    Thanks for your help. I want to mark this as solved, how do I go about doing that?

    Best regards,

    littleone
    I don't know how to set a thread as 'solved'; as a topic starter you have a button named 'thread tools' (or similar) that seem to have an option for what you want.

    kind regards,

    Jos

Similar Threads

  1. Replies: 0
    Last Post: 09-23-2010, 04:25 PM
  2. NoClassDefFoundError: Can't find the class
    By Mestika in forum New To Java
    Replies: 1
    Last Post: 09-23-2010, 03:17 PM
  3. Replies: 6
    Last Post: 04-15-2010, 03:50 AM
  4. Could not find main class
    By Andyj in forum New To Java
    Replies: 2
    Last Post: 10-06-2009, 12:47 AM
  5. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 04:07 PM

Posting Permissions

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