• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot compile using 'Swing' library.

 
Greenhorn
Posts: 5
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all. I'm a Java newbie (sort of).
My question is this: Why won't this code compile:

****************************************
package tutorials;

import javax.swing.*; // <== This package does not exist anywhere on my machine!

public class HelloWorld {

private JFrame frame; // <== Cannot resolve symbol: 'JFrame'

public void testCreate() {
System.out.println ("Hello World");
}
}
****************************************

My Java environment:
Originally, I had SE JDK 1.6.0-45 installed but that did not seem to contain any 'swing' package(s).
So, I uninstalled that and downloaded and installed another version from Oracle: SE JDK 1.7.0-51.
This made no difference whatsoever.

(The rest of the story: Windows 7 Pro-64 (up-to-date) with Intelli-J Community Edition v. 13.0.3, JUnit 4.11)
This stuff has been working great for 6 months with every other aspect of Java.

Where are the 'swing' packages?
Do I need to install J2EE instead?
I've 'Googled' this question for several hours and nobody seems to be able to tell me where the swing packages are located.

Can someone please help ?
I am fresh out of ideas.

Thanks a big, fat, hairy bundle.

-- BugMeister
 
Author
Posts: 160
11
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder if IntelliJ is using some unexpectedly old version of Java instead of the newer ones that you've installed. Certainly both JDK 1.6 and 1.7 have the Swing classes.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried compiling on the command line rather than from IntelliJ. That way you can easily check the version of the java compiler that is being used by typing
javac -version
 
G. Miller
Greenhorn
Posts: 5
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mr. Burd.

The IDE seems to indicate that it is using Java 1.7.0-51 in the Project Structure settings for Platform Settings SDKs.
I can attach a screenshot if you like.
I do not know where to find the settings in the IDE that indicate which version of Java it uses by default, but
I did navigate to the Jetbrains\IntellJ\jre\jre\bin\ directory and found 'java.exe' and ran it and it said: 1.7.0-40.

So, I *think* it's using Java v.1.7 no matter what, and yet, it cannot resolve the symbol 'JFrame'.

I also tried taking advantage of the 'code-completion' feature of IntelliJ by typing:

"import javax." and then letting it display all the sub-packages that are available (minus the quotes, of course).
Here is the list that is displayed:

*
crypto
microedition
net
security
sql
xml

=-=-=-=-=-=-=-=-=

But no swing.
I *thought* that 'swing' was a part of the JDK by default since at least 1.4 (and possibly earlier), but obviously, I am mistaken.

Thanks for any insight you may be able to offer.

Regards,

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, javax.microedition isn't one of the packages in the standard Java API. So I suggest that what you're looking at is some kind of Java ME installation. I'd go back and get Java SE installed instead.
 
G. Miller
Greenhorn
Posts: 5
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ms. Neal. That was a very educational suggestion.
Compiling from the Windows command line, the code compiles (and runs, although it does not utilize a JFrame object, it does compile it without issue.).
So, it would seem that the problem is isolated to IntelliJ.
I shall now attempt to build an entire screen widget using the command line.
But even if this is successful, it still leaves the problem of why IntelliJ can't find the 'swing' library unresolved.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Paul has already pointed out, you are likely pointing IntelliJ at the wrong Java installation.
 
G. Miller
Greenhorn
Posts: 5
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone. I'm almost there.
The Swing stuff works fine from the command line.

However, it's not quite as simple as saying "IntelliJ is pointing at the wrong installation of the Java", because I only keep one JDK
on the machine. That said, I'm also aware the IntelliJ comes with it's own version of Java pre-loaded and it appears to be 1.7.0-40.
But that does not guarantee that it is the SE version. I just downloaded a fresh JDK and performed an MD5 checksum against it
and compared that with the one I downloaded yesterday (& installed) and it confirms that the correct version (SE 1.7.0-51) is available at the command prompt.

So, the problem is somewhere within the bowels of IntelliJ and I will have to dig around until I can un-root the built-in version and force it
to use the externally installed version. (By external I mean external to IntelliJ.)

Does anyone know how to re-configure IntelliJ to resolve this issue?
(Or am I relegated to digging until my fingernails are all broken off?) ;)

And thanks for the quick responses. I sort of expected this to take days. I did not know you folks were actively monitoring the forums.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G. Miller wrote:Does anyone know how to re-configure IntelliJ to resolve this issue?



So now that we've established it's an IDE problem and not a Swing problem, let me move the thread to the IDEs forum.
 
G. Miller
Greenhorn
Posts: 5
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr. Bibeault - my deepest apologies.

You were absolutely, without question, correct.

I had inadvertently reconfigured my IntelliJ Project SDK to point to the Android SDK. (Doh!)

In the case anyone is interested, you change it like this:

* Start IntelliJ
* Click on File
* Click on Project Structure
* Click on Project
* Examine the field "Project SDK:" and use the 'pull-down' arrow to select the appropriate JDK for your project.
(Note: IntelliJ was able to see SE JDK 1.7.0-51 since the JDK was installed on Windows.)

So yes, yes it was as simple as saying that "IntelliJ was probably pointing at the wrong SDK".
(Boy, Howdy! As if Android SDK could do Swing!)

So again, I realize that the only reason for opening my mouth is to switch feet.

Thank you Mr. Bibeault for being patient with this greenhorn.
I'll try to listen more attentively in the future should I stumble across any more problems. (Which I undoubtedly will.)
And thanks to all who participated in my re-education.

This issue is resovled. (IMHO)

Regards,

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting back with the answer, G Miller! And yes, the forums are here for any and all questions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic