• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

trouble importing javax.swing.JOptionPane

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


Hope this helps...
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah...my bad. I came into Java at 1.4.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Where does a nanny get ground to air missles? Protect this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic