Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Boolean Input Question.

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Boolean Input Question.

    Hi, This is a really simple question but I've been stuck on this for a while now. Does this line of code read a boolean input from the console?

    userInput = TextIO.getlnBoolean();

    I have looked up the textbook I am using(Introduction to Programming Using Java, Sixth Edition by David Eck) and this is what it says to put for a boolean input. The bottom console says that there is an illegal boolean input value. But the console wont let the user input anything the program just stops at that line. The console highlights this line as the problem but I can't see a problem.

    Any help would be appreciated.

    Thanks David


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Boolean Input Question.

    What package is the TextIO class in? Is there documentation for that package's classes?
    What does the doc say?

    The console highlights this line as the problem
    Are you saying your IDE is saying there is a problem with your code?
    What error message do you get if you compile the program using the javac program?
    Last edited by Norm; August 2nd, 2012 at 11:24 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Input Question.

    Hi,

    The error message is:

    Exception in thread "main" java.lang.IllegalArgumentException:

    Illegal boolean input value.
    Expecting one of: true, false, t, f, yes, no, y, n, 0, or 1
    at TextIO.errorMessage(TextIO.java:950)
    at TextIO.getBoolean(TextIO.java:826)
    at TextIO.getlnBoolean(TextIO.java:619)
    at Definitions.guess(Definitions.java:163)
    at Definitions.main(Definitions.java:22)

    Thanks David

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Boolean Input Question.

    What does the method's doc say about when it will throw that exception?
    Are you surprised that the exception was thrown? What did you enter that the method was trying to read and create a boolean value from?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Input Question.

    Hi,

    As I said the program dosen't allow me to enter a thing it just stops there and the error message comes up. I'm sorry I don't know what the method's doc is.

    Thanks David

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,186
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Boolean Input Question.

    I don't know what the method's doc is.
    Its very important that you read the documentation for classes and their methods. Trying to code and use classes and their methods can be frustrating and a waste of time without reading the doc.

    I have no idea what the TextIO class does so I can't say why it is doing what it is doing.

    Try using the Scanner class instead. That is part of the Java SE classes and is well documented.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Boolean Input Question.

    Hi,

    Thanks I will try the scanner class.

    David

Similar Threads

  1. Arraylist input help, quick question.
    By Sarmen in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 11th, 2012, 01:37 PM
  2. beginner question--boolean expressions
    By ninjaBob in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 17th, 2012, 02:12 PM
  3. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 09:56 AM
  4. Simple Input Dialog Question
    By tabutcher in forum Java Theory & Questions
    Replies: 0
    Last Post: March 1st, 2010, 10:10 PM
  5. Java operaton on boolean varibles
    By big_c in forum Java Theory & Questions
    Replies: 5
    Last Post: May 12th, 2009, 04:40 AM