[5093] in java-interest
Re: Problem with File I/O and IOException
daemon@ATHENA.MIT.EDU (Greg Ewing)
Mon Jan 29 00:26:52 1996
Date: Mon, 29 Jan 1996 11:29:07 +1100
From: grege@optimation.com.au (Greg Ewing)
To: s323027@student.uq.edu.au
Cc: java-interest@java.sun.com
> From NewsGroup_comp-lang-java Fri Jan 26 08:20 EST 1996
> From: NewsGroup_comp-lang-java
> >From: s323027@student.uq.edu.au (Kylie Moseling)
> Subject: Problem with File I/O and IOException
> Date: 25 Jan 1996 13:01:54 GMT
> Nntp-Posting-Host: student2.cc.uq.oz.au
> X-Newsreader: TIN [version 1.2 PL1]
>
Kylie,
You have not assigned anything to `f', so it is reporting a nullPointerEx
when you try to use it. See the corrections below.
GREG
grege@optimation.com.au
> Hi,
>
> I'm just learning java, and I'm hoping that some kind person can help me.
>
>
> I've written a very small test applet which generates the error
>
> java.lang.NullPointerException
> at test.main(test.java:19)
>
>
> The class goes like this:
>
>
> import java.applet.Applet;
> import java.io.RandomAccessFile;
> import java.io.IOException;
>
>
> public class test extends Applet
> {
> static RandomAccessFile f;
>
> static public void main(String argv[])
> {
> try {
> new RandomAccessFile("test.txt","rw");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f = new RandomAccessFile("test.txt", "rw");
> } catch (IOException e) {
> System.out.println("Could not open file.");
> }
>
> try {
> f.writeChars("Hello World !!!");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this won't complain anymore
> } catch (IOException e) {
> System.out.println("Could not write to file.");
> }
>
> try {
> f.close();
> } catch (IOException e) {
> System.out.println("Could not close file.");
> }
> }
>
>
> }
>
>
> I would really appreciate some help with what is probably a stupid error.
>
>
> Thanks in advance.
>
>
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com