Results 1 to 4 of 4
  1. #1
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default Can not run my java program

    I just did a test program, after a successful compiling, I got the .class, but I don't know why I can't run it. Does anybody know why?
    Following is the output:

    C:\Program Files\Java\jdk1.6.0_11\bin>java Add2Int
    Exception in thread "main" java.lang.NoClassDefFoundError: Add2Int
    Caused by: java.lang.ClassNotFoundException: Add2Int
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    Could not find the main class: Add2Int. Program will exit.

    Following is the program:

    class AddTwoInt
    {
    public static void main(String args[])

    {
    int a=5, b=8, c=0;

    c=a+b;

    try {
    System.out.println("The sum is:" + c);
    } catch (throwable e) {
    System.out.println(e.getMessage());
    }
    }
    }

  2. #2
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    Oops, never mind. I figured it out. I want to delete the post, but don't know how...

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    I don't think you can.

    But you could point out your mistake for those who are newToJavaToo!

  4. #4
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    The problem was that I have the file saved as Add2Int.java, the class name was AddTwoInt. When I ran with "java Add2Int", it couldn't find the main.

    It ran nicely after I rename "AddTwoInt" to "Add2Int".

Similar Threads

  1. Java Program for doing FTP
    By Rajesh_J2EE in forum New To Java
    Replies: 1
    Last Post: 12-06-2008, 03:35 AM
  2. Java program help
    By Crystaliss in forum New To Java
    Replies: 1
    Last Post: 11-20-2008, 04:46 PM
  3. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  5. java program
    By nehasahu in forum New To Java
    Replies: 5
    Last Post: 07-12-2007, 12:05 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
  •