LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2004, 12:38 AM   #1
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Rep: Reputation: 34
getting javax.swing.* to appear


On the unix labs at my university all of the java running performs without flaws - gui's included. Here is a simple java file that i try to run on both systems:
Code:
/**
 * simple.java
 */
import javax.swing.*;

public class simple {
        public static void main( String args[] ) {
                JOptionPane.showMessageDialog( null, "Can you see me?" );
        }
}
then i type:
Code:
$ javac simple.java
and it compiles fine (the prompt is returned without any output). On the university's unix machine, running the program produces what i expect - a single message dialog, with the text "Can you see me?" in it, with an OK button. However i cannot do that on my machine (mandrake 10 official). I have j2re1.4.2_05, j2sdk1.4.2_05, and jdk1.3.1_12 in /etc/java/.

When i type "java simple" on my machine, i get this:
Code:
$ java simple
Exception in thread "main" java.lang.NoClassDefFoundError: simple
   at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.4.0.0)
   at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.4.0.0)
   at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.4.0.0)
   at __libc_start_main (/lib/tls/libc-2.3.3.so)
$
any idea? i'm clueless...

thanks in advance
 
Old 10-04-2004, 12:46 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Have you installed java in /etc/java?

That's strange. Because java is usually installed in /usr/java.

I think that it's trying to use the GNU gcc java instead of Sun Java and that's where the error occurs.
 
Old 10-04-2004, 12:49 AM   #3
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Original Poster
Rep: Reputation: 34
so.. how would I fix it?
 
Old 10-04-2004, 12:54 AM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
As a quick fix try calling java using the full path like in
Code:
/etc/java/j2sdk1.4.2/bin/java simple
substitute the path I gave with the actual path in which your Sun java executable resides on your system.
Or if you want to fix the whole problem, then make symbolic links to all the Sun java executables in your /usr/bin directory.

PS. I just tried your program on my system and it works fine.
 
Old 10-04-2004, 01:15 AM   #5
hack_in_box
LQ Newbie
 
Registered: Sep 2004
Location: India
Distribution: Fedora core1, PCQ Linux2004, SuSE8
Posts: 13

Rep: Reputation: 0
or u can set the JAVA_HOME variable and export it on the cmd line. Another method is set the above variable in ur .bash_profile. That should do the trick.
 
Old 10-04-2004, 01:46 AM   #6
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
It sounds more like a CLASSPATH problem. try adding . (current dir) to your CLASSPATH
 
Old 10-04-2004, 10:24 AM   #7
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Original Poster
Rep: Reputation: 34
I'm sorry, i meant the path /usr/java! I somehow miss-typed that. Apologies. Anyway


I have

/usr/java/j2re1.4.2_05/bin/java

/usr/java/j2sdk1.4.2_05/bin/java
/usr/java/j2sdk1.4.2_05/bin/javac

and take a look at this:
Code:
$ whereis java
java: /usr/bin/java /usr/share/java
$ ls -l /usr/bin/java
lrwxrwxrwx  1 root root 22 Jul  5 21:12 /usr/bin/java -> /etc/alternatives/java*
$ ls -l /etc/alternatives/java
lrwxrwxrwx  1 root root 23 Jul  5 21:12 /etc/alternatives/java -> /usr/bin/gcj-java-3.3.2*
That's just a messy system of linking...

Either of the /usr/bin/j2*/bin/java work on my other programs that use javax.swing.JFrame, but somehow javax.swing.JOptionPane isn't working.. maybe i don't have it?

*edit, ok.. here's what i found out: I compiled it with javac which is in the same path above (doing the 'whereis'), and when i recompiled the .java file (any) with the javac found in the /usr/java/j2sdk--/bin/javac and then ran it with the java in the same folder it worked! so my other java thing must just not be... good? Anyway thank you for all of your help (i would not have been able to get it myself)! :-D I will redo the links in /etc/bin when i have time later (for now i have bash aliases set).

-alex
 
Old 10-05-2004, 09:48 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
so my other java thing must just not be... good?
Your other java is the gnu java compiler, with its strengths and weaknesses, and is unrelated with Sun's products (j2re & j2sdk).

Quote:
I will redo the links in /etc/bin
No, in /usr/bin !
 
Old 10-05-2004, 10:06 AM   #9
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Original Poster
Rep: Reputation: 34
arg! yes, /usr/bin... sorry. /etc/ will die
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
what is import javax.swing.*; Dutchman Programming 4 06-16-2005 10:12 AM
javax.media.jai.RenderedOp to byte[] csfalcon Programming 0 04-13-2005 11:34 AM
Bluez and javax.comm ---> NoSuchPortException philipina Programming 1 06-24-2004 09:16 AM
javax.swing doesn't work israel Programming 4 02-19-2004 11:59 PM
javax comm for suse linux kingshrimp Linux - Newbie 4 11-26-2003 09:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 AM.

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