• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Another topic from ("x" cannot be resolved to a variable)

 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help on a topic that is too beginner, but I can't understand why I get this error (I look for it in another topics and try to solve it, but that error keeps coming)

Help would be greatly appreciated.





 
Rancher
Posts: 4739
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why I get this error


Please copy the full text of the error message and paste it here. It has important info about the error.
 
Joseph Soler
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the code java, i put in // in where is the current error and what that say

here is the error:

"height2 cannot be resolved to a variable "

tnks for the help
 
Ranch Hand
Posts: 47
1
IntelliJ IDE Slackware Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
height2 is out of the scope of the while's conditional statement. try declaring the variable outside of the do block, like this.
 
Eric Arnold
Ranch Hand
Posts: 47
1
IntelliJ IDE Slackware Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a nice article you might consider reading, to kinda reinforce this lesson.
 
Joseph Soler
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohhhh...

oh, now i see the problem

thanks a lot dude, for the example and the link
 
Marshal
Posts: 75711
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have got an answer, but there is lots more you should improve.
  • 1: Only use underscores _ in identifiers when you are defining constants.
  • 2: Capitalise all words in a ClassName. GenderAndHeight please, not gender_and_height. Look at this old document about naming.
  • 3: Don't double‑space code. Eric Arnol has corrected that error already.
  • 4: Never use == false or == true. Again Eric Arnold has shown you the correct way to use false values.
  • 5: Be sure to be consistent with your indentation. Line 31 is slightly to the right of line 24. Another thing Eric Arnold corrected. Also spacing. Make sure the } after do is followed by a space.
  • Why are you using option panes? That is a very old‑fashioned programming style.
     
    Joseph Soler
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    why I use panes?
    because I'm still a newbie in programing in any type of language of programing :v , I use the things that I was learning before (maybe there may better options to do what I was try to write)

    but, anyway, thanks a lot for the corrections about my form to programming
     
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You didn't initialized variable "height2" outside the scope of "do while" loop
    rather you initialized "height2" inside "do while" loop which made it a local variable instead of global variable.
    You should initialize "height2" at the beginning of "do while" loop.


    Here is your corrected code:-

    Staff note (Knute Snortum) :

    Be sure to read the previous comments before you post.  Eric Arnold already posted this solution.

     
    Campbell Ritchie
    Marshal
    Posts: 75711
    354
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Joseph Soler wrote:. . . I use the things that I was learning before . . .

    Find out about a Scanner object. If you have a book recommending option panes, don't use it; that book is probably seriously out of date.
     
    You know it is dark times when the trees riot. I think this tiny ad is their leader:
    free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    reply
      Bookmark Topic Watch Topic
    • New Topic