this is my code: i dont know where is the error I search every where but I didn’t get the answer so any one of you guys have the answer for my question? because I’m new to files, and i want to complete this project
import java.util.Scanner; import java.io.*; public class eManager implements Serializable { Scanner s = new Scanner(System.in); private long copyId; private int event; private int totalT; public eManager(long copyId) { this.copyId = copyId; } public void Calc(int eventss) { int teckits = 10; this.event = eventss; int events = eventss; if (events % 10 > 4) teckits++; teckits += (events - 10) / 10; totalT = teckits * events; } public long getCopyId() { return copyId; } public int getTotalT() { return totalT; } public void data() { System.out.println("**<@" + copyId + "> --> " + totalT + "**"); } public void data2() { System.out.println("**<@" + copyId + "> --> " + event + "**"); } }
Advertisement
Answer
Everything field inside a Serializable
has to either be null, or be refer to an instance of a Serializable
class (and that instance’s fields have to be null or Serializable too).
A Scanner
isn’t Serializable
because that would need to transitively serialize the stream it is reading from, and it can’t do that, for example if it’s reading from the input stream of the process or a network connection, so you can’t serialize an instance of this class.
You don’t even seem to use s
, so just remove it?