 |
 |
 |
 |
| Programming & Packaging A place to discuss programming and packaging. |

14th May 2005, 05:28 AM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 25

|
|
|
Java error
I just finished reading a Java for Dummies book and I'm trying to get the Java SDK to work.
Compiling code works just fine, but as soon as I try and run a program I get this:
Exception in thread "main" java.lang.NoClassDefFoundError
I've fiddled with setting the CLASSPATH in bashrc, and I've even tried setting it using -cp and -classpath, but I k eep getting the same error.
Any ideas?
Last edited by mbdayton; 14th May 2005 at 10:59 PM.
|

14th May 2005, 11:37 PM
|
 |
Retired Community Manager
|
|
Join Date: Feb 2004
Location: Seattle, WA, USA
Age: 56
Posts: 3,423

|
|
Firstly, you don't want to set CLASSPATH and, if you're just beginning, I wouldn't worry about -cp either.
If you can't figure it out from the Dummies book, I'd recommend starting with the Java Tutorial off of http://java.sun.com/docs/index.html
If, after that, you can't figure out what's going wrong, you'll need to post where your .java file(s) are, how you're starting the SDK, and what version of the SDK you're using (java -version).
__________________
Linux User #28251 (April '93)
Professional Java Geek :cool:
|

14th May 2005, 11:46 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 25

|
|
|
thanks, I'll start with the java tutorial.
|

15th May 2005, 12:17 AM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 25

|
|
|
Well I was able to compile and run a program succesfully, but now it only works while I'm logged in as root. What's the deal?
BTW, thanks for moving my post to the right forum. I'm loving this place!
|

18th May 2005, 07:51 PM
|
 |
Registered User
|
|
Join Date: Jan 2004
Posts: 456

|
|
You probably need to create a file like this:
more /etc/profile.d/java.sh
Code:
export JAVA_HOME="/opt/jdk1.5.0_03"
export JAVA_PATH="$JAVA_HOME"
export PATH="$PATH:$JAVA_HOME/bin"
As far as the original error you recieved, you probably ran into the same problem I did. (learning java too)
Say you created a java file called ForLoop.java and you compiled it and ended up with a ForLoop.class, BUT inside your .java you labeled it
Code:
public class ForLoop
You can simply mv/cp ForLoop.class to ForLoop and it should work. Or I "guess" if you had:
Code:
public class ForLoop.class
It would have worked.
Checkout "Head First Java 2nd Edition" by Kathy Sierra & Bert Bates, good book!
__________________
aka "jlc" on irc.
Main Desktop:
Rawhide x86_64
MSI K8N NEO2 Platinum
AMD Athlon 64 3200+ Winchester @ 2350MHz
CORSAIR XMS TWINX1024-3200C2 2GB
BFG Nvidia GeForce 6800GT OC @ 370MHz 256MB GDDR3
2x80GB SATA 150 Segate Raid 0
|

18th May 2005, 11:10 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 25

|
|
Quote:
You probably need to create a file like this:
more /etc/profile.d/java.sh
|
So I'm creating a seperate file from my my bashrc file?
If so do I need to reference this file from my profile file?
|

18th May 2005, 11:33 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Minnesota, USA
Age: 27
Posts: 7,909

|
|
|
~/.bashrc should work, but only for your user.
|

19th May 2005, 12:32 AM
|
 |
Registered User
|
|
Join Date: Jan 2004
Posts: 456

|
|
|
When you log in, environment variables are set from /etc/profile (for all users).
Then all the files in the /etc/profile.d directory.
Then ~/.bash_profile, then ~/.bashrc.
So either way will work.
__________________
aka "jlc" on irc.
Main Desktop:
Rawhide x86_64
MSI K8N NEO2 Platinum
AMD Athlon 64 3200+ Winchester @ 2350MHz
CORSAIR XMS TWINX1024-3200C2 2GB
BFG Nvidia GeForce 6800GT OC @ 370MHz 256MB GDDR3
2x80GB SATA 150 Segate Raid 0
|

19th May 2005, 07:21 AM
|
 |
Registered User
|
|
Join Date: Feb 2005
Age: 45
Posts: 60

|
|
When you execute the file, are you doing
Code:
java ProgramName.class
because for whatever reason, it freaks out the JVM whn you do that. You should just type without the .class extension. Sorry if this isnt the fix, but I remember having this same problem when I came back to java after a couple of years away.
__________________
System Specs:
Compaq 2195us
Fedora Core 3 - Athlon XP-M 2500+
- 512 MB RAM
- Radeon IGP 320M
- 40 GB Hard Drive
- Broadcom 802.11g Wireless
- ~2.5 Hrs Battery Per Charge
|

19th May 2005, 02:58 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 25

|
|
|
thanks to everyone for the help. I haven't had the time to work on it for awhile, but I'll report back once I have a chance to try some of this stuff.
This is the first programming I've ever done, so this has been helpful.
|

19th May 2005, 03:48 PM
|
 |
Registered User
|
|
Join Date: Jan 2004
Posts: 456

|
|
Quote:
|
Originally Posted by Unkemptwolf
When you execute the file, are you doing
Code:
java ProgramName.class
because for whatever reason, it freaks out the JVM whn you do that. You should just type without the .class extension. Sorry if this isnt the fix, but I remember having this same problem when I came back to java after a couple of years away.
|
thx for that bit of info, i just kept renaming  I"ve been java programming all of 7 days now  or atleast learning.
__________________
aka "jlc" on irc.
Main Desktop:
Rawhide x86_64
MSI K8N NEO2 Platinum
AMD Athlon 64 3200+ Winchester @ 2350MHz
CORSAIR XMS TWINX1024-3200C2 2GB
BFG Nvidia GeForce 6800GT OC @ 370MHz 256MB GDDR3
2x80GB SATA 150 Segate Raid 0
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 23:30 (Thursday, 23-05-2013)
|
|
 |
 |
 |
 |
|
|