• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why will my java program not run with command prompt?  RSS feed

 
Zukias Trunchbull
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My java program runs fine in NetBeans, but when I try to run it from the class directory after I have set the path to the directory containing my main class and then trying "java InputGraph" (which is my main class) I get the following error:

C:\java\InputGraph\build\classes\inputgraph>java InputGraph
Exception in thread "main" java.lang.NoClassDefFoundError: InputGraph (wrong nam
e: inputgraph/InputGraph)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)


Any help on fixing this would be much appreciated!
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess your class is in package inputgraph (autogenerated by the IDE).
So, to run your program from a command prompt go to folder
C:\java\InputGraph\build\classes
and execute command
java inputgraph.InputGraph

Then, forget you have an IDE.
Then, get familiar with Notepad++, javac and java.
Then, read about classpath.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote: . . . inputgraph . . . C:\java\InputGraph\build\classes . . . jjava inputgraph.InputGraph . . .
I or i? Careful.

It is usually better not to set a System CLASSPATH at all.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you had the I and i correct there, but it shows how much confusion you can get if you have the name of the project the package and the class so similar to one another.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Pawel Pawlowicz wrote: . . . inputgraph . . . C:\java\InputGraph\build\classes . . . jjava inputgraph.InputGraph . . .
I or i? Careful.

It is usually better not to set a System CLASSPATH at all.

Did I write anything about setting system classpath?

Campbell Ritchie wrote:I think you had the I and i correct there, but it shows how much confusion you can get if you have the name of the project the package and the class so similar to one another.

Is it my invention? Or maybe OP's?
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote: . . . Did I write anything about setting system classpath?
No, but you mentioned classpath at all, and that can confuse beginners into thinking they need to set a classpath.

. . . Is it my invention? Or maybe OP's?
It was OP's.

Sorry. I didn't mean to imply you were wrong.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Pawel Pawlowicz wrote: . . . Did I write anything about setting system classpath?
No, but you mentioned classpath at all, and that can confuse beginners into thinking they need to set a classpath.

If they actually read about classpath they would know that they do not need to set a system variable named CLASSPATH
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of places, however, where you can read bad and misleading information telling one to set a classpath.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!