Results 1 to 6 of 6
- 12-28-2011, 11:24 PM #1
Member
- Join Date
- May 2011
- Posts
- 84
- Rep Power
- 0
Getting "cannot resolve" errors with java.swing
Hello,
I am trying to create a simple window using swing.
I get this errors when trying to compile:
Could someone please explain to me what is happening?Java Code:Exception in thread "main" java.lang.Error: Unresolved compilation problems: SwingUtilities cannot be resolved JFrame cannot be resolved to a type JLabel cannot be resolved to a type JButton cannot be resolved to a type at SwingExample.main(SwingExample.java:12)
PHP Code:import java.awt.FlowLayout; import java.swing.JButton; import java.swing.JFrame; import java.swing.JLabel; import java.swing.SwingUtilities; public class SwingExample { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame("Swing Example Window"); f.setLayout(new FlowLayout()); f.add(new JLabel("Hello world!")); f.add(new JButton("Press me!")); f.pack(); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setVisible(true); } }); } }
-
Re: Getting "cannot resolve" errors with java.swing
I'm surprised that the imports didn't cause errors because Swing imports shouldn't be java.swing.XXX but javax.swing.XXX.
So change this:
to this:Java Code:import java.awt.FlowLayout; import java.swing.JButton; import java.swing.JFrame; import java.swing.JLabel; import java.swing.SwingUtilities;
orJava Code:import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities;
Note that the awt imports do not derive from javax but rather from java as you are doing now -- so don't change them.Java Code:import java.awt.FlowLayout; import javax.swing.*;
- 12-28-2011, 11:28 PM #3
Member
- Join Date
- May 2011
- Posts
- 84
- Rep Power
- 0
Re: Getting "cannot resolve" errors with java.swing
It works now. Thank you :)
Hmm.. Surprisingly I took the code from Wikipedia. Do they have the wrong code there?
-
Re: Getting "cannot resolve" errors with java.swing
You're welcome!
Look for yourself -- what do you see?Hmm.. Surprisingly I took the code from Wikipedia. Do they have the wrong code there?
- 12-29-2011, 12:59 AM #5
Member
- Join Date
- May 2011
- Posts
- 84
- Rep Power
- 0
Re: Getting "cannot resolve" errors with java.swing
I could swear these x were not there an hour ago...
-
Similar Threads
-
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
How can I fix "Cannot resolve symbol" error
By yma16 in forum IntelliJ IDEAReplies: 4Last Post: 05-16-2011, 12:28 PM -
"Cannot find symbol" errors in Java
By 23Zone in forum New To JavaReplies: 1Last Post: 02-17-2010, 07:13 AM -
genjar - "Unable to resolve:"
By angryboy in forum New To JavaReplies: 0Last Post: 06-28-2009, 06:48 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks