• Post Reply Bookmark Topic Watch Topic
  • New Topic

readLine() problem  RSS feed

 
Will Hoskins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I typed in a ready-made class from a textbook and can not get it to compile. In part it reads:

import java.io.*;
public class <name> {
....
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
....
}

When I try to javac it, I get "canot find symbol" on readLine.

Any ideas?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the *exact* error message?

Is the variable inputLine declared and in scope?
 
Will Hoskins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
inputLine is declared as a String, then there is a "try" block including the attempted read. The code (GameHelper.java) is copied from page 112 of Head First Java Feb. 2005 edition.

The error messages follow. (Presumably the second will go away when the first is resolved). The pointers (before the lines are collapsed to the left margin) are at "readLine" on the first error, and "." on the second.

C:\jdk6\test2008>javac GameHelper.java
GameHelper.java:9: cannot find symbol
symbol : method readLine()
location: class GameHelper
inputLine = is(readLine());
^
GameHelper.java:10: cannot find symbol
symbol : variable length
location: class java.lang.String
if (inputLine.length == 0) return null;
^
2 errors

[ February 10, 2008: Message edited by: Will Hoskins ]
[ February 10, 2008: Message edited by: Will Hoskins ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
inputLine = is(readLine());

This does not match the code you originally posted. Please be sure to accurately post your code. Otherwise, time is wasted chasing red herrings.
 
Will Hoskins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:

This does not match the code you originally posted. Please be sure to accurately post your code. Otherwise, time is wasted chasing red herrings.


Bonk! (I could have had a V8.) Thank you much. The problem is solved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!