Results 1 to 7 of 7
- 09-29-2012, 03:41 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 9
- Rep Power
- 0
Cannot find symbol: This is driving me insane!
Hey all, I am getting a compile error: Cannot find symbol. Can anybody please help me resolve this issue?
ThanksJava Code:import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TFTest extends JFrame { public TFTest() { JTextField tf = new JTextField("0",5); Listener listener = new Listener(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tf.addActionListener(listener); add(tf); pack(); setVisible(true); } public class Listener implements ActionListener { public void actionPerformed(ActionEvent e) { tf.setText("It worked!"); } } }
- 09-29-2012, 04:48 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Cannot find symbol: This is driving me insane!
Which symbol is the compiler message talking about? And which line of your code does it refer to?
Basically, "cannot find symbol" occurs whenever you use an identifier (eg method or variable) and the compiler has no clue what you are talking about. This can be because of a typo (misspelling) or, in the case of methods, because you are not supplying the right number and types of arguments. With variables the compiler will complain if the variable is not "in scope": what this means is that the variable must be declared in the same {} block as you use it, or in an enclosing one.
- 09-29-2012, 05:19 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 9
- Rep Power
- 0
Re: Cannot find symbol: This is driving me insane!
The error tells me that tf is not found in the ActionListener class
- 09-29-2012, 05:57 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Cannot find symbol: This is driving me insane!
Then it would appear that tf (which was declared in the TFTest constructor) in not in scope once you get to the actionPerformed() method of the Listener class.
- 09-29-2012, 09:02 AM #5
Member
- Join Date
- Sep 2012
- Posts
- 9
- Rep Power
- 0
Re: Cannot find symbol: This is driving me insane!
and how do I go about fixing that?
- 09-29-2012, 09:15 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Cannot find symbol: This is driving me insane!
You declare tf so that its scope includes the actionPerformed() method.how do I go about fixing that?
Did you understand what I meant by "scope"?
- 09-29-2012, 11:39 AM #7
Member
- Join Date
- Sep 2012
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Cannot find symbol
By dest in forum New To JavaReplies: 3Last Post: 04-03-2012, 05:38 PM -
Cannot find Symbol
By webbby in forum New To JavaReplies: 3Last Post: 04-14-2011, 12:51 AM -
Driving me insane - Program not working as it should ><
By mainy in forum New To JavaReplies: 1Last Post: 08-27-2009, 01:20 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks