This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes NoClassDefFoundError in a simple program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

NoClassDefFoundError in a simple program

harish gowda Java green
Greenhorn

Joined: Nov 30, 2009
Posts: 4
am running this program:


package com.test;

public class Test1 {

/**
* @param args
*/
public static void main(String[] args) {

System.out.println("Hello");

}

}

I got the following..not able to figure out the reason? Any help would be welcome..Thanks


C:\tmp\Test1>java Test1
Exception in thread "main" java.lang.NoClassDefFoundError: Test1 (wrong name: co
m/test/Test1)
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$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: Test1. Program will exit.


Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Look at your path. You declare Test1 class to be in com.test package, that means class file should reside in /com/test folder. But your class is in tmp folder. That's why you got this error. So either remove package declaration from your file or put it in the right folder.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

Once is enough. UseOneThreadPerQuestion. I'm closing this one.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Consider Paul's rocket mass heater.
 
subject: NoClassDefFoundError in a simple program