Mark Oneill

Greenhorn
+ Follow
since Feb 08, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Mark Oneill

Thank you very much for your help Dave Tolls I will add a bunch of System.out.println() calls and see if I can see whats going on and where it's breaking!

Have a fantastic weekend!
1 week ago
Doubles and Integers are fundamental data types you cant just interchange between the two, as you will loose data!

But you can cast them if you are happy with loosing precision.

Like:

double d = 1.2;

int i = (Integer) d;

2 weeks ago

Dave Tolls wrote:Sorry, it's me being a bit dim.
The deserialisation skips normal object creation, so that instantiation of the List doesn't happen.



Ahh I did not know that! Thank you so much for spreading the knowledge

So if I create a method something like:



And then call this method in the "blank" constructor



That should stop my NullPointerExceptions?
2 weeks ago
Apologies for my dumbness I haven't coded in almost 10 years!
2 weeks ago


I thought I had initialised the ArrayList? :/
2 weeks ago
Thanks for the replies guys - a great community here. And I am glad to see the site is still up and running - I used to visit here often in Java 1.2 days ;) and have recently started to get back into programming. . .

I am saving each players data to an individual player binary file using



I'm then reading in the file again at a later date using





Within the Player class (version 2) I have a ArrayList with a method addToChatLog(String input) {array_list.add(input;}

It was when I called this method from a version 1 Player that I got the NullPointerException.

I suspect I may be doing something fundamentally wrong :/



2 weeks ago
The methods shown were just to illustrate. So it's not about optional attributes. The Player class is work in progress and things will be added to it over a period of time. Version 1, Version 2, Version 3, etc. With each new version new getter and setter methods will be added.

I was thinking about setting the serialVersionUID for each version to something different so I could identify if the object was an "old" one or not.

I suppose I will have to load the old object, check the serialVersionUID, pull out the getter methods return values, store them in temporary attributes and then reload them into a new object.

I was just hoping there was an easier/simpler way to do it than this.
2 weeks ago
Hi everyone,

I'm writing a program that writes a Player file using an ObjectOutputStream is there a way to easily update old Objects that have been read, into new Objects with the newly added method calls?

To illustrate:

Old 'A' saved object has;

constructor()
getName()
getHeight()

New 'B' object type has;

constructor()
getName()
getHeight()
getAge()

Clearly when I load object 'A' from the Player class, and then call getAge() I get a NullPointerException due to the object 'A' not having the version 2s ('B's) getAge() method. Is there a simple way to "upgrade" my objects as they are read in?

I hope that I'm making sense



2 weeks ago