Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.