Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Code is working, but errors are still present?

Learning about loops and booleans to censor certain words; I came across an error in my code despite following the code as is in the tutorial.

The error reads as follows in the console, however the loop function still functions as intended:

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:30: error: cannot find symbol
} while(noun.equalsIgnoreCase("dork") ||
^
symbol: variable noun
location: class TreeStory
TreeStory.java:31: error: cannot find symbol Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you? 20
Your name: Dan
Your adjective huge
Your noun: jerk
That language is bad. Try again.

Your noun: nerd
That language is bad. Try again.

Your noun: nerd
That language is bad. Try again.

Your noun:


and here is the code I have written below:

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
    String ageAsString = console.readLine("How old are you?  ");
    int age = Integer.parseInt(ageAsString);
    if (age < 13) {
      // Exit code
      console.printf("Sorry you are not old enough!\n");
      System.exit(0);
    }
    String name = console.readLine("Your name:  ");
    String adjective = console.readLine("Your adjective  ");
    String noun;
    boolean isInvalidWord;
    do {
      noun = console.readLine("Your noun:  ");
      isInvalidWord = (noun.equalsIgnoreCase("dork") ||  
                       noun.equalsIgnoreCase("jerk") ||
                       noun.equalsIgnoreCase("nerd"));
      if (isInvalidWord) {
        console.printf("That language is bad.  Try again. \n\n");
      }
    } while(isInvalidWord);
    String adverb = console.readLine("Your adverb:  ");
    String verb = console.readLine("Your verb:  ");

    console.printf("My first TreeStory:\n--------------------\n");
    console.printf("%s is a %s %s. \nThey are always %s %s.", name, adjective, noun, adverb, verb);
}

}

Also after clearing the console the error still shows up and shows previous inputs as well?

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:30: error: cannot find symbol
} while(noun.equalsIgnoreCase("dork") ||
^
symbol: variable noun
location: class TreeStory
TreeStory.java:31: error: cannot find symbol
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you? 20
Your name: Dan
Your adjective huge
Your noun: jerk
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you? 20
Your name: mike
Your adjective huge
Your noun: jerk
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you?

any pointers on this is much appreciated!

2 Answers

Steven Parker
Steven Parker
231,275 Points

I pasted the code into a new workspace and it compiled without errors.

To allow a more accurate replication of your environment, make a snapshot of your workspace and post just the link to it here (and when pasting code, always use use Markdown formatting).


UPDATE: using your snapshot, I am still unable to replicate the error. It works fine for me. But there are some rather peculiar things in your output sample. It looks like multiple compile/execution attempts, despite the "clear" command. It could be you're just looking at the result of past runs before you fixed some errors.

I suggest closing the console pane and opening it again (with "Show Console" in the "View" menu). That should give you a completely clean console. Then try your build & run command one time.

If that does the job, perhaps you are having trouble with the "clear" command with your particular browser and/or OS. You might want to make a bug report to the Support staff.

https://w.trhou.se/qxguynlp6g

this is the screenshot of the work space, I tried running the program again and it ran without displaying said errors as before.

This again was the error message that the console showed, along with the repetitions even when clearing the console using clear && javac TreeStory.java && java TreeStory

(thank you for the tips on markdown)

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:30: error: cannot find symbol
} while(noun.equalsIgnoreCase("dork") ||
^
symbol: variable noun
location: class TreeStory
TreeStory.java:31: error: cannot find symbol
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you? 20
Your name: Dan
Your adjective huge
Your noun: jerk
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you? 20
Your name: mike
Your adjective huge
Your noun: jerk
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
How old are you?
Steven Parker
Steven Parker
231,275 Points

See the update added to my answer.