compile problem

OK, its humbling to have to post someting like this.. but anyway.

I'm writing a simple test program to simply write the date to a new file every however many seconds. But I just can't get it to compile. It tells me that the class MyFileWriter should be declared as abstarct - but I just can't see why. Can anyone set me staright on this one?

Thanks folks.

import java.util.*;

import java.io.*;

import java.nio.*;

import java.nio.channels.FileChannel;

import java.nio.channels.ReadableByteChannel;

class MyFileWriterextends TimerTask

{

abstractpublicvoid run();

{

System.out.println("File written");

}

}

class MyFileWriterTest

{

publicstaticvoid main(String args[])

{

MyFileWriter fileWriter =new MyFileWriter();

Timer fileTimer =new Timer();

fileTimer.schedule(fileWriter, 2000, 2000);

try

{

for(int n = 10; n > 0; n--)

{

Calendar calendar = Calendar.getInstance();

String time =new String(calendar.get(Calendar.HOUR) +":" + calendar.get(Calendar.MINUTE) +":" + calendar.get(Calendar.SECOND) +":" + calendar.get(Calendar.MILLISECOND));

FileOutputStream fos =new FileOutputStream (new File("Users/damian/Desktop/Test"));

FileChannel channel= fos.getChannel();

ByteBuffer fileText = ByteBuffer.allocate(time.length());

byte[] bytes = time.getBytes();

fileText.put(bytes);

fileText.flip();

channel.write(fileText);

fileText.clear();

fos.close();

}

System.out.println("File written");

Thread.sleep(5000);

}

catch (InterruptedException e)

{

System.out.println("Main thread interrupted");

}

fileTimer.cancel();

}

}

[3166 byte] By [damian-milanoa] at [2007-9-29 13:26:03]
# 1
You have declared your method "run" as abstract.Skip this keyword from your code, and I think that it'll work...
jWolf789a at 2007-7-15 3:41:53 > top of Java-index,Archived Forums,Java Programming...
# 2
OK, I tried that, now it gives me another error:MyFileWriter.java:16: missing method body, or declare abstract (ie the line with the run() method!)
damian-milanoa at 2007-7-15 3:41:53 > top of Java-index,Archived Forums,Java Programming...
# 3

hie,

u wrote :

abstract public void run(); <(the methode is declared)

{// what is this ? to which method belongs this ?

System.out.println("File written");//

}//

i think u should create a class that inherits from MyFileWriter and redefine the method run.

good luck,

caroline

caroline2330a at 2007-7-15 3:41:53 > top of Java-index,Archived Forums,Java Programming...
# 4
I got it - it was the semi colon at the end of the method run()
damian-milanoa at 2007-7-15 3:41:53 > top of Java-index,Archived Forums,Java Programming...