|
-
Dec 5th, 2005, 05:07 PM
#1
Thread Starter
Hyperactive Member
noClassDefFoundError [SOLVED]
I get the following error when trying to run this class file. It seems to compile fine but I just can't get it to run.
Any help would be appreciated.
This is what the java source file contains:
Code:
public class HelloJava {
public static void main( String[] args ) {
System.out.println("Hello, Java!");
}
}
Also tried:
Code:
import javax.swing.*;
public class HelloJava {
public static void main( String[] args ) {
JFrame frame = new JFrame( "Hello Java!" );
JLabel label = new JLabel("Hello Java!", JLabel.CENTER );
frame.getContentPane( ).add( label );
frame.setSize( 300, 300 );
frame.setVisible( true );
}
}
Last edited by gjon; Dec 10th, 2005 at 01:26 AM.
-
Dec 5th, 2005, 05:16 PM
#2
Re: noClassDefFoundError
try "java HelloJava.class"
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 5th, 2005, 05:20 PM
#3
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
Don't think I need to add that part unless there is something I am missing from the book I am reading.
The book states:
Now that we've got something presentable, let's take a moment to compile and run this example. Place the text in a file called HelloJava.java.
Now compile this source using the Java compiler, javac:
% javac HelloJava.java
This produces the Java bytecode binary class file HelloJava.class.
You can run the application with the Java virtual machine by specifying the class name (not the filename) as an argument:
% java HelloJava
Either way, it is still giving the same error.
Thanks for making an attempt to solve but it appears to be something else.
Last edited by gjon; Dec 5th, 2005 at 05:36 PM.
-
Dec 5th, 2005, 05:44 PM
#4
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
I tried running this in netbeans and jcreator.
Both with no luck, but they say that main is missing.
Not sure how to use those ide's so I'll stick to trying to get it to work in dos.
Edit: welp, it works in BlueJ just fine. I don't understand why all these things are working and not working the way they are.
Whats the difference? But my concern is why I can not get it to work via dos. I don't want to use BlueJ.
Thanks in advance.
Last edited by gjon; Dec 5th, 2005 at 05:48 PM.
-
Dec 5th, 2005, 05:46 PM
#5
Re: noClassDefFoundError
Are you sure you installed Java 1.4 SE?
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 5th, 2005, 05:49 PM
#6
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
I think I have installed everything there is to be installed, will the previous post help explain? Would BlueJ work without the SE?
-
Dec 5th, 2005, 05:51 PM
#7
Re: noClassDefFoundError
AS long as it's java, it'll work.
I don't know what is the problem in your case, but I think re-installing java is a smart move
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 5th, 2005, 06:04 PM
#8
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
k. i guess i'll have to. Could you do me a favor and provide me with the link to the exact sdk, or jdk or jre I need to dl and install. It can be confusing when you look at javasun's site to figure out exactly what you need. I went with the netbeans complete package. I thought that would include everything.
Thanks in advance.
Or maybe I am trying to run it in the wrong directory?
Here is teh directory I am trying this from in dos.
E:\Program Files\J2SEE1_4SDK\jdk\bin
Last edited by gjon; Dec 5th, 2005 at 06:08 PM.
-
Dec 5th, 2005, 06:07 PM
#9
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 5th, 2005, 06:09 PM
#10
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
Just to be sure it isn't a directory thing, did you see the edit to the post above?
I really don't understand the classpath thingy so maybe that has something to do with it.
O well, its just a stab, thanks for the link. I'll check it out.
Edit: o ya, i see that program files has a space in that directory> could that be the problem? having installed it to a folder with a space in the name?
-
Dec 5th, 2005, 07:20 PM
#11
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
Welp after doing some searching. I found that this is what I needed to type at the command prompt to get it to work properly.
java -classpath . HelloJava
Can someone explain what this is actually doing with the classpath?
-
Dec 5th, 2005, 08:46 PM
#12
Fanatic Member
Re: noClassDefFoundError
Perhaps you have a classpath environment variable with no "." as one of the value. Should be .;SomePath;YetAnotherPath;AndSoOn. Try looking at your classpath environment variable.
-
Dec 5th, 2005, 09:08 PM
#13
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
Thats the thing, I don't understand classpath at all. How do you go about setting it? Where is it? And what is it for?
I did some searching on javasuns site but there were mentions of class path in some really advanced programs syntax so I could not gather anything from it.
Thanks in advance!
-
Dec 6th, 2005, 12:34 AM
#14
Fanatic Member
Re: noClassDefFoundError
It's the way java finds the classes. Classes are compiled by default to become the smallest unit as the .class file. When you go using these classes, java has to find these. That's the path of classes are used for.
Assuming you have WinXP, go to System Properties. On Advanced Tab, click Environment Variables. Check either User variables or System variables. See if you can find a variable named classpath and check the variable value. Add "." to the variable. Hope this helps.
-
Dec 6th, 2005, 01:02 AM
#15
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
E:\Program Files\J2SE\lib\ext\QTJava.zip
is the current variable for classpath. Should i make it
E:\Program Files\J2SE\lib\ext\*.*
-
Dec 6th, 2005, 03:03 AM
#16
Fanatic Member
Re: noClassDefFoundError
Make it .;E:\Program Files\J2SE\lib\ext\QTJava.zip
Give a dot "." for java to find classes on your current directory.
-
Dec 6th, 2005, 01:43 PM
#17
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
omg, that worked. I was so like no way, but it did. LOL
What the heck does .; do?
Thanks a lot, you helped me get past this huge dilemma as files stopped compiling once I created a seperate class.
Kudos!
-
Dec 6th, 2005, 06:58 PM
#18
Re: noClassDefFoundError
Search the forum, I think I posted a very long explanation on classpath once.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 6th, 2005, 08:09 PM
#19
Thread Starter
Hyperactive Member
Re: noClassDefFoundError
I tried a search for class path and found this to be very helpful:
You need to modify the environment variable PATH.
Depending on your OS you may be able to do this with AUTOEXEC.BAT. If not, you will need to go into System Properties. I'm not familiar with all the flavors of Windows, but in Win2K, right-click My Computer and select Proberties. Select the Advanced tab and click Environmental Variables. Scroll down the System variables list, select Path and click Edit. In NT (if I remember correctly) you have to go into Environment in the Control Panel
To make the change to Path, you simply need to add the path to your javac compiler. For example, if you have a basic path variable, it will look something like this:
C:\WINNT\system32
All you will need to do is add the location of javac.exe to the list so it looks like this:
C:\WINNT\system32;c:\jdk1.3\bin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|