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 trialAnthony Hendrix
3,395 PointsSimple Java Problem
Hi!
I have a problem with a simple Java program. If you followed the basic Java course you should be able to help me.
This is my program:
////////////////////////////////////////////////////////////////////////////////////////
import java.io.Console;
public class NewPractice {
public static void main(String[] args) { Console console = System.console();
console.printf("Hello! Welcome to the new refurbished knight hall.\n");
String knightStatus = console.readline("Are you a knight? ");
if (!knightStatus.equalsIgnoreCase("yes")) { console.printf("Sorry... You are not allowed into the knight hall."); System.exit(0); }
console.printf("Ah, dear knight. Please enter!");
}
} ///////////////////////////////////////////////////////////////////////////////////////
So you probably don't need any instructions on what i'm trying to run. Here is the error code when i try to compile, using javac NewPractice.java
//////////////////////////////////////////////////////////////////////////////////////
treehouse:~/workspace$ javac NewPractice.java
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
NewPractice.java:9: error: incompatible types: String cannot be converted to boolean
String knightStatus = console.readline("Are you a knight? ");
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
/////////////////////////////////////////////////////////////////////////////////////
So what's the issue here?
1 Answer
Samuel Ferree
31,722 PointsI don't see any javadoc for why 'console.readline("")' would return a boolean, but the method signature for getting a String from the console is console.readLine() with a capital L.
Java is case sensitive, so it looks like some other method was going to be called, one that apparently returns boolean.
Anthony Hendrix
3,395 PointsAnthony Hendrix
3,395 PointsThat did it. Thank you.
looks like it was a beginners error :,)