Erik Price
Posts: 39
Nickname: erikprice
Registered: Mar, 2003
|
|
Re: Quick BufferedWriter question
|
Posted: Jul 11, 2003 10:24 AM
|
|
The problem is that although you have declared a BufferedWriter reference variable named dist, you haven't actually assigned it to any objects. Therefore it has no value, and when the compiler sees dist.write(), it doesn't understand what object it should invoke write() on.
You must assign the dist reference variable a value. You have three choices:
1) Use a constructor: BufferedWriter dist = new BufferedWriter(); 2) Use the return value of a method: BufferedWriter dist = someOtherObject.getWriter(); 3) Assign null: BufferedWriter dist = null;
You probably want Option 1. If you choose option 2, you will need to have another object with a method that returns a BufferedWriter or a subtype of BufferedWriter. If you choose option 3, your code will compile but will throw a NullPointerException at runtime.
|
|