0

This is my main class:

public class Table extends java.applet.Applet implements Runnable
{
    public void init()
    {
        Balla.addBall();
    }
}

This is the Balla method:

public static void addBall()throws IOException
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }

Now my question come from when I complie it. It tells me that I have an unreported IOException in the init method, but when I add the throws IOException on the method it tells me:
error: init() in Table cannot override init() in Applet

How can I get around this and/or how can I fix this without modifying to much of everything?

JWPM77
  • 5
  • 3

1 Answers1

0

change this

public static void addBall()throws IOException
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }

to

public static void addBall()
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        try
{
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }
catch(Exception e)
{
}
}

and see if it works

Satya
  • 8,693
  • 5
  • 34
  • 55
  • I mean it got rid of the error but it doesn't actually ever seem to write to the file. – JWPM77 May 11 '14 at 04:39
  • add this line in catch block and see the error : e.printStackTrace(); – Satya May 11 '14 at 12:05
  • that's elementary then, change the path to other drive e.g. D: , and you should be through. Also please accept the answer – Satya May 12 '14 at 02:27