• Post Reply Bookmark Topic Watch Topic
  • New Topic

errror cannot find symbol  RSS feed

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't figure out why the instance member myItemString is not recognized.

see textFieldOne.setText(item.myItemString);

in actionPerformed below.



And


 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the actual name. There are two letters missing.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I make the name the same the compiler complains that I am
"hiding a variable".

However, It compiles and runs.

But I get no output on the textField.

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geoff,

Look at how you're calling myItemString the second time. The problem lies there.

John.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I must not be able to see the forest for the trees.

based on the objectReference.fieldName paradigm

object reference is item, and fieldName is myItemString

hence item.myItemString

Go ahead and hit me with at tree so I can see the light.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try this. My guess is that when you made the names match, you left in the "String " on your line 12, so the compiler thought you were declaring a NEW, second String called ItemString.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred basically answered what I was going to answer with. Just note the change in variable name or create a getter for your Item's itemString variable.

Also, quick question.



Unless you plan on altering the string when you create your Item constructor, isnt' this going to grab the text from your textField and replace the textField's text with its own text? If you are debugging waiting for a change in your textField I would be wary of that.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try this. My guess is that when you made the names match, you left in the "String " on your line 12, so the compiler thought you were declaring a NEW, second String called ItemString.



Yes, I did leave the “String”.



Unless you plan on altering the string when you create your Item constructor, isnt' this going to grab the text from your textField and replace the textField's text with its own text? If you are debugging waiting for a change in your
textField I would be wary of that.

Item item = new Item(textFieldOne.getText());
textFieldOne.setText(item.myItemString);



Actually I was playing around with the output. For example:

textFieldOne.setText(“ “ + itemMyItemString);
And WOWiee.
Since I removed the “String” from the constructor it works.

Thanks everyone. Now I can sleep tonight.



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!