LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   getting javax.swing.* to appear (https://www.linuxquestions.org/questions/programming-9/getting-javax-swing-%2A-to-appear-238483/)

student04 10-04-2004 12:38 AM

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

vharishankar 10-04-2004 12:46 AM

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.

student04 10-04-2004 12:49 AM

so.. how would I fix it?

vharishankar 10-04-2004 12:54 AM

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.

hack_in_box 10-04-2004 01:15 AM

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.

mirradric 10-04-2004 01:46 AM

It sounds more like a CLASSPATH problem. try adding . (current dir) to your CLASSPATH

student04 10-04-2004 10:24 AM

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

jlliagre 10-05-2004 09:48 AM

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 ! ;)

student04 10-05-2004 10:06 AM

arg! yes, /usr/bin... sorry. /etc/ will die


All times are GMT -5. The time now is 10:12 AM.