aspose file tools*
The moose likes Beginning Java and the fly likes trouble importing javax.swing.JOptionPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble importing javax.swing.JOptionPane" Watch "trouble importing javax.swing.JOptionPane" New topic
Author

trouble importing javax.swing.JOptionPane

Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
this is the compile error message:

Class or interface `javax.swing.JOptionPane' not found in
import.
import javax.swing.JOptionPane;

Thanks in advance.


I'm a Hood Ornament
Alan Jump
Greenhorn

Joined: May 25, 2005
Posts: 26


Perhaps you're trying to be too specific in your import. Try using this:


Hope this helps...
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
Are you using an older version of Java. I believe Swing is added to the standard classes since 1.3. If you are using an older version you can add the swing classes to the classpath (I don't know what the jar was called but it exists.) Maybe it is a better idea to use a newer JDK anyway, especially if you want to use Swing.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

My guess is that you're using Visual J++ or another old IDE you found the disks for. Java's come a long way since then. Visual J++ partially supports Java version 1.1, while the current version is 1.5 -- and an awful lot has changed in the many intervening years.

Visit java.sun.com to get a brand-new Java Developer's Kit.


[Jess in Action][AskingGoodQuestions]
Alan Jump
Greenhorn

Joined: May 25, 2005
Posts: 26
Originally posted by Manuel Moons:
I believe Swing is added to the standard classes since 1.3.


The J2SE 1.5 API documentation still shows Swing as a javax package.

API Overview - Java 2 Platform SE 5.0
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
The J2SE 1.5 API documentation still shows Swing as a javax package.


But the original swing (swing 1.0) classes were in the package com.sun.java.swing and subpackages thereof. (They weren't shipped with the Jdk either, they were a separate download)
[ June 01, 2005: Message edited by: Timmy Marks ]
Alan Jump
Greenhorn

Joined: May 25, 2005
Posts: 26
Ah...my bad. I came into Java at 1.4.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Try using something else from the swing package and see what happens. You should definately be using.



just doing



is generally not considered good coding practice. Though you can try it just for trouble shooting purposes.

Chances are that the compiler can't find the swing package. Either you don't have it (by using an older version of java, as has been suggested) or it's not in your classpath.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673

May not be considered good practice, but is definately the norm when programming large GUI applications.
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
Hello all and thanks for the swift replies. I am using jdk1.5.0_02 in a linux computer. It could be a classpath or path problem. Here's what I did in my /etc/profile


I created a "java" link to my jdk1.5.0_02 folder. It still gives me the same compile error message.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

How is JDK 1.5 getting installed into "/opt/java/bin?" I don't believe this is where Sun's installer puts it.

Try this: type

javac -J-version

and let us see what happens.
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
Hi Ernest I typed "javac -J-version" and this came out:

java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
Charlie Goth
Ranch Hand

Joined: Feb 26, 2004
Posts: 60
Maybe I'm wrong but the message looks different to what I get if I import a non-existant class. Could there be something else wrong with the code?

Normlly (for me atleast) I'd get:
cannot find symbol
symbol : class Fish
location: package javax.swing
import javax.swing.Fish;
...................^ (without the dots)
1 error


SCJP (77%)
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
Posting this so that others may know how to set classpath in Redhat linux:

I was able to solve my classpath problem. Now I don't need to type:

javac -classpath . filename

and in my test programs i can now type the real class name. e.g.

import javax.swing.JOptionPane;

this is what I did to my classpath:



I don't make classes as root.

 
Don't get me started about those stupid light bulbs.
 
subject: trouble importing javax.swing.JOptionPane