• Post Reply Bookmark Topic Watch Topic
  • New Topic

initializing an Array of Objects  RSS feed

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have this as a global array, but "rectCount" isn't = to anything until I read in the number.





Now the problem is that the array is already initialized as an empty array, so what I'm asking is there a way to reinitialize the array AFTER I get a value for rectCount?? If not what is the best approach to going about this?
 
Paul Clapham
Sheriff
Posts: 22831
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. You can reinitialize it using code like you already have in line 11 in your second code fragment. The only problem with that line is that it declares a local variable. You don't want to do that, you want to simply assign the new array to the existing class-level variable.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Of course. You can reinitialize it using code like you already have in line 11 in your second code fragment. The only problem with that line is that it declares a local variable. You don't want to do that, you want to simply assign the new array to the existing class-level variable.


Ah that was easy haha, thank you very much!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To keep your object's internal data structure's integrity, perhaps you can use a local variable until you've fully deserialized the array, and then overwrite the current array with the new one. All your original code would need is this piece of code between lines 17 and 18: If for whatever reason the deserialization of one of the array elements fails you will not have an array with some elements missing (null values). Instead, you will still have the old value of the array. Only if everything succeeds will you have the new deserialized array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!