Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble importing javax.swing.JOptionPane

 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the compile error message:

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

Thanks in advance.
 
Alan Jump
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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


Hope this helps...
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alan Jump
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah...my bad. I came into Java at 1.4.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

May not be considered good practice, but is definately the norm when programming large GUI applications.
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic