This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Why won't it recieve input?
Posted by Zach Keatts on December 11, 2000 at 4:43 PM
I have written the following code. For some reason when the program comes to the line String inputLine=in.readLine(); it doesn't even stop to allow the user to input a value. When this happens it leaves the value inputLine null, and then the program ends up throwing a NullPointerException. Am I missing something?!?!? (here's the code) import java.util.*; import java.io.*; public class Parse { final static int MAX_LINES=500; public static void main(String[] args)throws IOException { boolean done = false; do { System.out.print("Please enter the file you wish to edit: "); ConsoleReader input = new ConsoleReader(System.in); String edit = input.readLine(); //input is received here try { FileReader reader = new FileReader(edit); done = true; } catch(FileNotFoundException e) { System.out.println("Sorry that file is not in the main directory.\n\n"); done = false; } finally { if(done) { final String DELIMITER="TEXT_END"; String[] document=new String[MAX_LINES]; FileReader reader = new FileReader(edit); BufferedReader in = new BufferedReader(reader); int i=0; String inputLine=in.readLine(); //this is my problem while(i { document[i]=inputLine; i++; inputLine=in.readLine(); } in.close(); reader.close(); Document stuff = new Document(document); boolean quit=false; while(!quit) { System.out.print(":"); String command=input.readLine(); parse(command); if(command.equals("q")) quit=true; } } } } while(!done); }
Replies:
|