File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues with cmd java command

 
Jared Malcolm
Ranch Hand
Posts: 54
Java MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone point me towards why I'm getting the error(s) below when trying to run a compiles java class? I'm sure it's something simple that I'm just not seeing... I've already taken and passed my SCJA and I'm just wanting to go to the next step... Just haven't used command line in about a year or so and have forgotten everything.

I've included the two classes I've built just to test everything and the lovely little string of errors below. The quoted text is my cmd prompt that is there just so you can see what I've tried. The javac command works perfect and both classes are compiled....just can't remember how to run the stupid thing.

Parent Class



c:\SCJP>javac com\jared2\Child.java

c:\SCJP>java com\jared2\Child
Exception in thread "main" java.lang.NoClassDefFoundError: com\jared2\Child (wro
ng name: com/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown 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)
Could not find the main class: com\jared2\Child. Program will exit.

c:\SCJP>java -classpath . com\jared2\Child
Exception in thread "main" java.lang.NoClassDefFoundError: com\jared2\Child (wro
ng name: com/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown 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)
Could not find the main class: com\jared2\Child. Program will exit.

c:\SCJP>cd com\jared2

c:\SCJP\com\jared2>java -classpath . Child
Exception in thread "main" java.lang.NoClassDefFoundError: Child (wrong name: co
m/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown 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)
Could not find the main class: Child. Program will exit.

c:\SCJP\com\jared2>java Child
Exception in thread "main" java.lang.NoClassDefFoundError: Child (wrong name: co
m/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown 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)
Could not find the main class: Child. Program will exit.


Thanks for the help! This is making me feel like a ratard.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\? /!
 
Shaikh Ali
Ranch Hand
Posts: 51
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to provide the fully qualified name of the class that you are running. Assuming your compiled packages exists in the current directory, try this:

 
Jared Malcolm
Ranch Hand
Posts: 54
Java MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hauke Ingmar Schmidt wrote:\? /!


My thoughts exactly!

Faraz Kadri wrote:You have to provide the fully qualified name of the class that you are running. Assuming your compiled packages exists in the current directory, try this:



Thanks so much this was the issue! So the final command including the directory structure was...

 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to express that all you need to do is replace the invalid package separator by valid separators. \ is invalid, / is valid, . is better.
 
Jared Malcolm
Ranch Hand
Posts: 54
Java MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hauke Ingmar Schmidt wrote:I wanted to express that all you need to do is replace the invalid package separator by valid separators. \ is invalid, / is valid, . is better.


Good to know. TY.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic