• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI update issue

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm having a problem that is a little hard for me to track down. I have my RMI installed and working fine...sort of. I can read my database, update, etc...but when I create a new record a problem arises. I am able to create it, but then if I try to read from the database again (without disconnecting from the registry) I get this message:
IndexOutOfBoundsException: Index: 35, Size: 35

If I disconnect from the registry and then reconnect, I can then come back and read everything just fine. So...something is not updating...or something. I can't find it. I am using an ArrayList to hold String[]'s of records, and each time the Read method is called, it is supposed to recalculate the record total. I don't have this problem when not using RMI. I can use the Scanner class to add and read all day without stopping anything so I have no idea.

As always, thanks.
Matt
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Matt!

Champ, first I have to ask: you implemented this feature of creating records just for testing purposes, right? Because we don't really have to implement such feature. That is, the create() method must be implemented in your Data class, but we don't have to offer this feature in the project.

Now, regarding your problem, it's sort of hard to say, but I think it is a problem with your algorithm. Try looking at the stack trace and see where in your code this happens. Try to see the line where it happens: what is the code that you have there?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some questions:
a) you are using an ArrayList, so I guess you are using a record cache?
b) why would your read-method need to recalculate the record total When you do a read nothing should change about your list (database), so the record total can never change, thus no need to recalculate this total.
c) if you create a record, then shutdown your registry and then reconnect, is the newly created record present in your database?
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

Thanks for the help! Actually, I found the problem. It was something very simple. I needed to move my ArrayList initialization into the method body. Duh on my part.

Yes, I am only testing the create method to make sure it works and that all is well. Nothing more. And when I shut the database down and restarted it, the new record was there. However, that problem is now solved.

As far as the logic of my program, when I create a record I am adding it to the end of the database - thus changing the length of my database and the total number of records present. My read() first gathers all of the records and puts them in an ArrayList<String[]>. Then when I want to call the method to return a particular String[], it is pretty straight forward. I don't know if that makes it clear what I am doing. I think explaining these type of things over the internet can be tough so I will just leave it at that.

You guys are great as always! Thanks a ton for your input (and patience).
Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic