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

Trouble with 'cannot find symbol' error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Very new to this and I'm having some difficulty getting this GUI dice game to compile. I'm using javac and notepad++ for this and i'm getting the following errors:

DiceGame.java:34: error: cannot find symbol
die2label = new JLabel();
^
symbol: variable die2label
location: class DiceGame

DiceGame.java:44: error: cannot find symbol
rollButton.addActionListener(new actionListener(){
^
symbol: class actionListener
location: class DiceGame

DiceGame.java:67: error: cannot find symbol
setVisibility(true);
^
symbol: method setVisibility(boolean)
location: class DiceGame
4 errors


My code is as follows:



I'm sure the problem is something trivial, but I guess that's all part of the learning process that I have to go through. Any help is appreciated.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. die2label and die2Label are not the same variable. Case matters.

2. There is no actionListener interface. It is ActionListener.

3. There is no setVisibility method in JFrame. There is a setVisible, though.

Programming is all about the small details.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thought I'd expand a bit on what I wrote before...I told you what the errors are, but how should you identify them yourself?

If you were using a dynamic language these are all errors that you wouldn't find until running the program. But the great thing about a statically typed language like Java is that it will catch these errors for you. To get the benefit of that, it's really important to read the errors carefully and understand what the they are telling you.

DiceGame.java:34: error: cannot find symbol
die2label = new JLabel();
^
symbol: variable die2label
location: class DiceGame


That should be fairly clear. The compile is telling you it doesn't recogise the variable die2label on line 34 (of the original file, not the listing posted). At that point you should be asking yourself "where is that declared?". Either you haven't declared it, or you've declared it somewhere but it's out of scope, or it's not declared correctly.

Well, you've declared it at the top of the class. And it's a member variable of the same class, so it should be in scope. So is it correct? That's when you should check the spelling, and realise it isn't right.

DiceGame.java:44: error: cannot find symbol
rollButton.addActionListener(new actionListener(){
^
symbol: class actionListener
location: class DiceGame


Here you're trying to use a built-in class, but the name of the class actionListener isn't recognised. What ought to be a red flag here is that it starts with a lower-case letter, and all Java classes in the standard libraries (and in your own code if you follow the standard conventions) start with upper-case. The naming conventions can help you recognise the error.

DiceGame.java:67: error: cannot find symbol
setVisibility(true);
^
symbol: method setVisibility(boolean)
location: class DiceGame


This time it doesn't recognise the method setVisibility. Either there is no method with that name, or there is one but it doesn't take a boolean argument. You haven't written a method called that, but your class is inheriting from JFrame so that's where you'd expect to find it. So what do you do next? Go check the documentation - the Javadocs are your friend (and will give you an answer much faster than a forum will!). So you go to javax.swing.JFrame, search the page, and discover that the method doesn't exist. But there is another method that sounds similar...
 
Jb Kendall
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Thought I'd expand a bit on what I wrote before...I told you what the errors are, but how should you identify them yourself?.....



Thanks for the reply, and you're absolutely correct in that it's all about paying attention to detail. I did make those changes and found a few other problems after it finally compiled. I did manage to figure those out and it seems to be all good now.
Thanks again.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic