• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execution error  RSS feed

 
Varun Prasad
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am trying to execute Test.class

Code for Test.java



I compiled Test.java using "javac -d . Test.java"
After which "pkg" directory got created.
Then I did the following

"cd pkg"
"java Test"

At which point I am getting the following error message.

C:\Users\varung\J\pkg>java Test
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: pkg
/Test)
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Can someone help ?
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did this code compile....recheck the '{}" pairs in program.

Manish
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to run the code from the right place.

Your class Test is in the package pkg. To run it, you have to put the directory that contains the package to the classpath, and specify the fully-qualified name of the class (package name + class name) to the 'java' command.

C:\Users\varung\J> java pkg.Test
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!