View Full Version : Java trouble
Zion Grail
Sep 28, 2004, 07:00 PM
Ever since I got the Java update I can't seem to run any of my classwork Java programs. No matter what I do, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError
Even in a simple HelloWorld! program I get this error. All of my programs, even ones that worked before, have started behaving like this.
Anyone else have this kind of problem?
*EDIT*
Even the ready-to-compile java files I got form the book's CD are acting like this!!
jeremy.king
Sep 28, 2004, 10:39 PM
How exactly are you trying to run these? Inside an IDE, from command line?
remember to compile your .java file first using javac and then run it with the java command (no extension on the file to be run)
For example
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("I love my mac.");
}
}
from terminal:
javac HelloWorld.java
this creates HelloWorld.class, and then
java HelloWorld
If this is completely obvious, I apologize, but every once and a while I brainfart and run the .java file through the java command and whoopsy...same problem
Good Luck
King Cobra
Sep 28, 2004, 11:00 PM
http://www.apple.com/downloads/macosx/apple/
If you're not running the latest version of Java, do that. There are Java 1.4.2 Update 2 and Update 1 links there. If those don't help, go through pages 2, 3, 4, etc. at the bottom of the page of the link above to find the Java 1.4.1 update (for Panther).
That is how he got the problem, the update caused It. I've been having a similar problem when compiling. However, no problems with exitsting java apps. I'm just hoping Apple can get Java 5.0 (1.5) out quickly.
TEG
Zion Grail
Oct 7, 2004, 01:01 PM
I can't be sure if it's the update or what, but I've found the problem - my classpath is blank. Nothin' in there. Gone.
I had to find where Java keeps it's classes on my system and manually set it, and I have to tell my system to inclde whatever current directory I've put my projects in my going to the command line, going to the directory i'm using, and typing
export CLASSPATH=$CLASSPATH:.
Then, to run anything in that directly, I *STILL* need to use the command
java -cp $CLASSPATH:. InsertClassNameHere
Then it works.
This is damn annoying, Apple. How did such a huge mistake get by you?
jeremy.king
Oct 7, 2004, 01:33 PM
I can't be sure if it's the update or what, but I've found the problem - my classpath is blank. Nothin' in there. Gone.
I had to find where Java keeps it's classes on my system and manually set it, and I have to tell my system to inclde whatever current directory I've put my projects in my going to the command line, going to the directory i'm using, and typing
export CLASSPATH=$CLASSPATH:.
Then, to run anything in that directly, I *STILL* need to use the command
java -cp $CLASSPATH:. InsertClassNameHere
Then it works.
This is damn annoying, Apple. How did such a huge mistake get by you?
You need to set your CLASSPATH. Its not Apples responsibility. If you want it to be more permanant, look into editing the appropriate .rc file associated with your shell. If you are using bash then modify the .bashrc in your home directory. If you are using tcsh then you will modify your .tcshrc file. Add that export command to either file and it will automatically get set when you log in.
Edit: I think you have to use the setenv command instead of export. So your command should look like
setenv CLASSPATH .:$CLASSPATH
bousozoku
Oct 7, 2004, 01:33 PM
That is how he got the problem, the update caused It. I've been having a similar problem when compiling. However, no problems with exitsting java apps. I'm just hoping Apple can get Java 5.0 (1.5) out quickly.
TEG
It's not surprising. There was also an issue when they revised to 1.4 and they eventually got a developer tools update together which took care of the problem. If you look at downloads for tools on the Apple developer site, you'll find the update in 2003.
Hopefully, they'll be swift about it.
Zion Grail
Oct 7, 2004, 03:40 PM
You need to set your CLASSPATH. Its not Apples responsibility. If you want it to be more permanant, look into editing the appropriate .rc file associated with your shell. If you are using bash then modify the .bashrc in your home directory. If you are using tcsh then you will modify your .tcshrc file. Add that export command to either file and it will automatically get set when you log in.
Edit: I think you have to use the setenv command instead of export. So your command should look like
setenv CLASSPATH .:$CLASSPATH
When I was running 10.2, it was already set and all I needed was the "java" and "javac" commands. If they did it before, I'd expect Panther to have it set up as well.
vBulletin® v3.6.10, Copyright ©2000-2009, Jelsoft Enterprises Ltd.