LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-07-2003, 08:20 PM   #1
degraffenried13
Member
 
Registered: Sep 2003
Posts: 228

Rep: Reputation: 30
Exception "NoClassDefFoundError" from java


I wrote a little program in java just to test whether everything was working well since I haven't tried using java with linux before. My program is as follows:

import javax.swing.JOptionPane;

public class test
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null, "Works");
System.exit(0);
}
}

It compiles fine, but when I run java test, I get "Exception in thread "main" java.lang.NoClassDefFoundError at ....[a lot of classes are defined after this at]" I thought it was because I didn't have gnome installed and I was running just from command prompt, but it won't work now that I have gnome installed either. Any ideas? Thanks
 
Old 09-07-2003, 10:46 PM   #2
evilRhino
Member
 
Registered: Oct 2002
Distribution: Red Hat 7.3, 8.0
Posts: 33

Rep: Reputation: 15
did you name the file test.java? the file name must match the class contained in the file (case sensitive I believe)

Good Luck!
 
Old 09-08-2003, 07:09 AM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Do you have your PATH and JAVA_HOME environment variables set?
 
Old 09-08-2003, 08:00 AM   #4
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Rep: Reputation: 30
To use the swing classes of java, the gui environment has to be installed in linux. Is it?
 
Old 09-10-2003, 09:26 PM   #5
degraffenried13
Member
 
Registered: Sep 2003
Posts: 228

Original Poster
Rep: Reputation: 30
To answer all of your questions in the hope of figuring this out. Yes, I have named it test.java and it compiled fine.

I have the PATH set to $PATH:$HOME/bin:/sbin:/home/myusername/java/bin/:/home/myusername/java/jre:$HOME/seti. I am not sure what the first and last ones are set to, but they were there when I opened my .bash_profile. If you can explain that too it would be great.

Finally, I have installed the gnome environment and have tried to run it from there, but I don't know if there is a seperate gui package that needs to be installed.

Thanks again for the help.
 
Old 09-11-2003, 07:05 AM   #6
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
You installed Java to your home directory? That is just fine, but it is a touch unusual. If that is so, then your PATH is set correctly. Now you probably need to set your JAVA_HOME environment variable. You need that pointing to the entire Java directory. So in your case it would be:

JAVA_HOME = /home/username/java
export JAVA_HOME

I'd put these lines in the same file you use to set your PATH and you may have to log out and back in for this to take hold.
 
Old 09-11-2003, 09:11 AM   #7
degraffenried13
Member
 
Registered: Sep 2003
Posts: 228

Original Poster
Rep: Reputation: 30
I appreciate the help, but that didn't seem to correc the problem either. Maybe I am jsut missing something.
 
Old 09-11-2003, 11:41 AM   #8
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
id never programmed java before a few days ago and i was having a discussion with someone - if typecasting a double to an int rounded, he said it did so i set about to show him it didnt, i wrote my first java program(to demonstrate this) in about 3mins, i then compiled it, had to sort out a few errors, then it took me an over an hour to make it run. you see the problem was i was typing 'java roundtest.class' to run it, which made sense to me because the file i wanted to run was called roundtest.class but for some strange reason to run roundtest.class you type 'java roundtest'

the point here is - type 'java test' instead of 'java test.class' and it'll run fine.
 
Old 09-11-2003, 11:45 AM   #9
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Yeah, it could be something silly. When I run into troubles like this, it usually is something completely dumb . Your code is fine. I just ran it on my machine without a problem, so we need to look at how you compile and run it.

I know this sounds stupid, but could you post the exact commands you use to compile it and the exact command you use to run it and the full error messages you get?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 02:11 AM
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window serve paragvd Programming 4 10-05-2004 03:35 AM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
Exception in thread "main" java.lang.NoClassDefFoundError: Lobais Linux - Software 19 06-23-2004 08:42 AM
Exception in thread "main" java.lang.NoClassDefFoundError: melinda_sayang Programming 2 04-27-2004 11:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration