Results 1 to 6 of 6
  1. #1
    castiel is offline Member
    Join Date
    Aug 2009
    Posts
    26
    Rep Power
    0

    Default Can't run my java program through cmd prompt

    hey, i've seen this error on quite a few forums but I still can't seem to fix it.

    I've changed the PATH environment variable and it's compiling fine with javac.
    i've set the class path like this: set CLASSPATH=.;C:\Program Files\Java\jdk1.5.0_15\lib
    and done echo %classpath% to verify that it was set.

    I've gone to the directory where the class files are located and after compiling successfully with
    javac, i try running the code and no matter what, i get that error!!! Can someone please tell me what i'm doing
    wrong and how i can fix this. Like i've even gone

    java -classpath . ReadStandardInput

    and it still hasn't worked, i still get same error, oh btw ReadStandardInput is just the name of my java file.

    This is the full error message from command prompt:


    C:\olddata\Documents and Settings\Chad\Chad\Uni Semester 2 2009\COMS3200\Data2\s
    rc\General>java -classpath . ReadStandardInput
    Exception in thread "main" java.lang.NoClassDefFoundError: ReadStandardInput (wr
    ong name: General/ReadStandardInput)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: ReadStandardInput. Program will exit.

    C:\olddata\Documents and Settings\Chad\Chad\Uni Semester 2 2009\COMS3200\Data2\s
    rc\General>



    I'd really appreciated if someone could help me fix this cos i really don't know what to do now.

    Thanx,

    Epically frustrated guy, cry++;

  2. #2
    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

    First of all, you've to check that class-path setup is correct. There is an easy way to do this, open the command prompt and type the command javac and hit enter. If you get a list of some options and explanations, congratz you've setup the class-path correctly.

    More looking at your error it's something wrong with your Java code. Can you show your code? This error can cause lots of things.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

  5. #5
    zande is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Re: Can't run my java program through cmd prompt

    change your dirctry to the dirctory wher ur compiled java program is risiding
    using
    simple command promput command CD path
    example if u stored ur java file in C:\test\helloworld.java then when u compile java stores the compiled file in the same dirctry then to run
    chnage the dirctry using cd c:\test then type
    at
    c:\test type java your java file hit return it should run
    otherwise check your class name
    good luck
    check your class name and
    Quote Originally Posted by castiel View Post
    hey, i've seen this error on quite a few forums but I still can't seem to fix it.

    I've changed the PATH environment variable and it's compiling fine with javac.
    i've set the class path like this: set CLASSPATH=.;C:\Program Files\Java\jdk1.5.0_15\lib
    and done echo %classpath% to verify that it was set.

    I've gone to the directory where the class files are located and after compiling successfully with
    javac, i try running the code and no matter what, i get that error!!! Can someone please tell me what i'm doing
    wrong and how i can fix this. Like i've even gone

    java -classpath . ReadStandardInput

    and it still hasn't worked, i still get same error, oh btw ReadStandardInput is just the name of my java file.

    This is the full error message from command prompt:


    C:\olddata\Documents and Settings\Chad\Chad\Uni Semester 2 2009\COMS3200\Data2\s
    rc\General>java -classpath . ReadStandardInput
    Exception in thread "main" java.lang.NoClassDefFoundError: ReadStandardInput (wr
    ong name: General/ReadStandardInput)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: ReadStandardInput. Program will exit.

    C:\olddata\Documents and Settings\Chad\Chad\Uni Semester 2 2009\COMS3200\Data2\s
    rc\General>



    I'd really appreciated if someone could help me fix this cos i really don't know what to do now.

    Thanx,

    Epically frustrated guy, cry++;

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

    Default Re: Can't run my java program through cmd prompt

    For Pete's sake, this thread is almost four years old; I'm closing it.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. clear screen prompt using java code
    By krunalpatel1410 in forum Advanced Java
    Replies: 9
    Last Post: 04-04-2009, 12:47 AM
  2. how to run windows command prompt in java parogram ?
    By indikasampath2000 in forum AWT / Swing
    Replies: 4
    Last Post: 12-16-2008, 06:51 AM
  3. Replies: 2
    Last Post: 12-03-2008, 01:24 PM
  4. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 03:01 PM
  5. Replies: 2
    Last Post: 08-06-2007, 09:16 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
  •