简体   繁体   中英

reading boolean value from a file to be printed

i'm having a trouble on my main class which is reading a boolean value from a .txt file... running my program gives me this message though compiling it doesn't give any errors

Reading course units... 1 Reading if course is taken... false Reading subject grade... 0Reading course year... 3 Reading semester... 2 Reading course number... IT 412a Practicum Reading descriptive title... 2 Reading course units... falsejava.lang.NumberFormatException: For input string: "false"

 at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Byte.parseByte(Byte.java:148) at java.lang.Byte.parseByte(Byte.java:174) at ChecklistDisplay.readChecklistInfo(ChecklistDisplay.java:74) at ChecklistDisplay.run(ChecklistDisplay.java:20) at ChecklistDisplay.main(ChecklistDisplay.java:8) 

and this is an example for my .txt file

4,2,IT 423,Information Systems Planning/Information Resources Management,3,false,0 year,term,course number,units,(subject taken?),subj grade

System.out.println("Reading if course is taken...");
                s = lineScan.next();
                System.out.print(s);
                boolean taken = Boolean.parseBoolean(s.trim());

please tell me if i ever you have the need to look at my full programs for review or my question is not clear enough

Boolean.parseBoolean does not throw java.lang.NumberFormatException .

So you are probably trying to do something like Integer.parseInt("false") somewhere in your code and it throws the exception. Without seeing all your code it is difficult to be much more specific.

Also the output does not correspond to the sample txt extract you have shown, which does not help understanding what the issue could be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM