Teen Programmers Unite  
 

 

Return to forum top

URGENT: Passing BufferedReader and PrintWriter objects to class constructors in Java

Posted by CodeRed [send private reply] at December 16, 2001, 06:30:28 PM

Here's a stripped down copy of my code:

In the main method:

BufferedReader infile = new BufferedReader(new FileReader(args[0]));
PrintWriter outfile = new PrintWriter(new FileWriter(args[1]));
Quiz thisquiz = new Quiz(infile, outfile);

In the Quiz class:

Quiz(BufferedReader inf, PrintWriter outf) throws IOException // Constructor
{
in = inf;
out = outf;
}

See I'm trying to pass 2 object to a class constructor but I get a NoSuchElement exception. Please help, I need this in the next couple hours

Posted by taubz [send private reply] at December 16, 2001, 06:53:52 PM

I don't see an error in the code. What line is the error on?

- taubz

Posted by CodeRed [send private reply] at December 16, 2001, 07:21:54 PM

Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:235)
at Quiz.readFile(GradeQuiz.java:99)
at Quiz.<init>(GradeQuiz.java:87)
at GradeQuiz2.main(GradeQuiz2.java:14)

The last line is the real error, it's when I try to pass infile and outfile to the Quiz constructor

Posted by CodeRed [send private reply] at December 16, 2001, 08:18:45 PM

Oh my god, I am sorry guys. It's late at night, I'm tired, and this huge project is due in the morning. I got a little paranoid when I couldn't get my code to work. The problem was I was formatting my input file wrong, and trying to use nextToken() when there were no other tokens on the line, I'm such an idiot.

Posted by gian [send private reply] at December 16, 2001, 08:23:04 PM

The first step to recovery is admitting you have a problem. But yes, I understand how something like that can happen.

Why didn't you ask on your brilliant OForum (or whatever) and get yourr 150 replies?

Posted by taubz [send private reply] at December 16, 2001, 08:50:18 PM

On a side note, "The last line is the real error" -- uhm, no. :) The real error is always in the first line of the stack trace that involves your source "at Quiz.readFile(GradeQuiz.java:99)". I guess you were *that* tired.

Good luck finishing it.

- taubz

Posted by CodeRed [send private reply] at December 16, 2001, 09:40:53 PM

ForumOC is more about overclocking and modding your comp. Yeah your right taubz, stack trace, these things just slip from my head now and then.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.