Results 1 to 9 of 9
- 09-16-2008, 04:04 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Exception in thread "main" java.lang.NoClassDefFoundError: welcome
Hi all,
Just started the install went well and the compiler (javac) works and creates .class files. However, everything I run "java" I always get the same error and to the best of my know I have done everything right.
The full error message is:
F:\My Documents\Java Files>javac welcome.java the file compiles ok
F:\My Documents\Java Files>java welcome
Exception in thread "main" java.lang.NoClassDefFoundError: welcome
Caused by: java.lang.ClassNotFoundException: welcome
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)
Can someone help please.
Many thanks in advance.
Peter
- 09-16-2008, 04:09 PM #2
What about posting your source?
Greetings, Martin Wildam.
- 09-16-2008, 04:11 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Here is the source
public class welcome
{
public static void main(String[ ] args)
{
String[ ] greeting = new String[3];
greeting[0] = "Welcome tp Core Java";
greeting[1] = "by Peter Mullan";
greeting[2] = " & asdjf";
for (String g : greeting)
System.out.println(g);
}
}
But it happens to any simple program I write.
Many thanks.
Peter
- 09-16-2008, 04:55 PM #4
First: A class name should start with an uppercase letter. Compiler should give you a warning on this.
Second: When launching your program with java you should specify the classpath commandline option - that is telling java where to find the class (I imagine your current dir is the the bin folder of the jdk ;) )
Third: When working with more classes they should be organized in packages and folder structure should be according to the package name - see for example here: The Java Package TutorialGreetings, Martin Wildam.
- 09-16-2008, 06:05 PM #5
Uppercase is only a convention. Lower case will work.
You don't need to set the classpath on your java command, but it is recommended.
Try: java -cp . welcome
Do you have a CLASSPATH environment variable set on your system? Does it have a . in it? That tells java to look in the current directory. Without the . it will NOT look in the current directory.
- 09-17-2008, 06:25 PM #6
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
It's working
Thank you for all your help.
The way I got it to work was to download and install Netbeans, which is a very nice java editor, which I was looking for anyway and it has the added advance in allowing you to execute your class files always, so all is good.
Once again many thanks for your help:)
Peter Mullan
- 09-17-2008, 07:07 PM #7
IDEs can be a help and a hinderance. If you rely on the IDE to solve problems as you've had, then you won't learn how java works in the OS environment. When you move out of the IDE you'll be lost. See you later.
- 09-17-2008, 08:08 PM #8
Actually I tried it also with NetBeans where I only had to choose the main class. But the IDE saves it and creates the appropriate config file for you.
I agree that you should know such basics anyway so that you can handle it also without the IDE.
But then it is good to have a tool that solves the library packaging and creates the jar file and appropriate distribution folder so that you can easily distribute everything necessary.Greetings, Martin Wildam.
- 09-18-2008, 12:55 PM #9
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Exception in thread "main" java.lang.NoClassDefFoundError: client Help
By b000m in forum New To JavaReplies: 6Last Post: 08-18-2008, 06:44 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
Exception in thread "main" java.lang.NoClassDefFoundError
By baltimore in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:07 AM -
Exception in thread "main" java.lang.NoClassDefFoundError
By carl in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:26 AM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks