• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializa an array  RSS feed

 
Rumilio Santa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys I am new at this stuff, I am trying to serialize an array and deserialize, I believe the serialization is working but I have been able to read the file

I am getting this

run:
Before serialization
arrays_serialize2.Account@9931f5
arrays_serialize2.Account@19ee1ac
arrays_serialize2.Account@9931f5
arrays_serialize2.Account@19ee1ac
After serialization
null
BUILD SUCCESSFUL (total time: 0 seconds)




 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What an Account class is?
I can't compile this without knowing the definition of Account class.

And please UseCodeTags (click this).

And welcome to the Ranch
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first problem is here:



If an exception is thrown, your code is simply ignoring it. You shouldn't do that. At least print the exception and its stack trace:

 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another problem:



Here you have two variables with almost the same name. So when you assign a value to the first one, and then serialize the second one, it's hard to understand why deserializing doesn't give you the value you assigned to the first one.
 
Rumilio Santa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the class

Here is the class Account

3 Views Tags (edit): array
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Account class doesn't implement Serializable. This would be a problem if you were actually trying to serialize any Account objects. But since you aren't (see my earlier post), that problem hasn't appeared yet.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see other problems, the serious one being that you are opening writers and never closing them. If you are using Java7, find out about try‑with‑resources, which is probably the easiest way to close those writers.

And since you are new (welcome to the Ranch ) I have added the code tags, and doesn't the code look a lot better
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some comments unrelated to your original question.

In method validatePIN you haveThis is an equivalent of saying:
if userPIN==pin is true then return true and if userPIN==pin is false then return false.
Did you notice that userPIN==pin is what you want to return?

So your method could look like this:

Another point is that double is not good for using with currency. I can understand that this is just an excercise but for currency you should use BigDecimal instead.
Read more here and here
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!