Hi people, I recently learn about 'Saving objects'. In order to practice it a little bit, I started making a problem. However I got stuck by a strange syntax error.
It says that I do not have the right amount of braces. But I do have the right amount of braces. Please help me out, And give me the correction. I will be pasting the code here:

import java.io.*;

public class network implements Serializable  { /* <-- one of the error is here  */

    try{
        tuna t=new tuna();
        FileOutputStream file = new FileOutputStream("pass.ser");


            ObjectOutputStream os = new ObjectOutputStream(file);
            os.writeObject(t);


    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}//Another of the error is here

Please help me out.
Thanks in advance

Recommended Answers

All 5 Replies

You can't write code directly into the class body like that. It needs to be inside a method.

Oh yeah! Thanks for pointing that out

AND you need to implement all of the methods specified in the Serializable class.

AND you need to implement all of the methods specified in the Serializable class.

Yes, all zero of them.

@OP
It appears that you are still struggling with how classes, objects, and naming conventions work. However, have no fear, the following links should address these issues.
Classes/Objects
Naming conventions
Also, by the less then appealing object name, I am assuming you are working with the NewBoston tutorials, which are in my opinion half-rate, and a money-grab. If you want a good video series, covering virtually all your going to need to know check out: this tutorial series

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.