0

Main Class:

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

Method:

 public class Balla
 {
    public static int balls=0;
    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+"\n");
        System.out.println("qqq");
        pw.close();
        fw.close();
    balls++;
    }
 }

It never actually does what I want it to do and I used the try and catch in the first place because I could not apply throws IOException to the init method.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
JWPM77
  • 5
  • 3

1 Answers1

0

Or in other words it is not calling the method addBall()

I do not see where you have instantiated Balla. Are you getting a NullPointerException ?

Also, your Exception block is empty. Add an e.printStackTrace() there and post the stack trace. That'll give u a clue as to what is going wrong.

This seems like a sandboxed applet and hence cannot write to a file. Quoting from the docs:

They cannot access client resources such as the local filesystem, executable files, system clipboard, and printers.

Sources:
1. What Applets Can and Cannot Do
2. How can an applet Read/Write files on the local file-system?

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221