I have been doing the RMI part for my SCJD certification, and now I realize how challenging the task to implement RMI is
Before I go on telling the problem that I have encountered, I will provide a brief explanation about the structure of my code:
1. My source code contains 2 interfaces, the first one is the DB interface (located in suncertify.db package), and the other one is called DBRemote interface (which is located in suncertify.rmi package).
The DB interface is the supplied interface given as part of the SCJD material, whereas the DBRemote interface is an interface created specifically for implementing the RMI.
If we refer to the sample code from Monkhouse SCJD guide, the DBRemote should extend the java.rmi.Remote & the interface DB. However, in my code, the DBRemote only extends Remote.
Thats because the methods declared in the supplied interface throw neither IOException nor RemoteException, which is required from implementing RMI. Therefore my DBRemote interface throws RemoteException for every method declared in it & is independent from the DB interface. The DBRemote interface also declare a very important method that the DB interface doesn't declare. This method reads the records stored in the db file
and returns the records in form of a list type Record (defined in Record.java). For additional information, this method also declared and defined in the class Data in Data.java that implements the DB interface.
2. The class DataRemoteImpl in DataRemote.java represents the remote object for my app. It implements the DBRemote interface. Obviously, the important method that is defined in the DBRemote, is also declared in the
Now the stage is all set, all I need to do is to make a remote connection request as shown in the code below:
There was no problem when running the server for the app. But, when running the client in network mode, the null pointer exception showed up on the client's command line window.
From line 24 & 35, I concluded that the request for the arraylist which contains the "Records" was performed successfully (partially successfull ) through localhost connection.
But the each element in the arraylist itself was null as indicated by the exception & by the getter methods for each element in a Record as it was called to extract the value to be displayed on the JTable.
I have ensured that the very important method that I mentioned earlier; which is declared in both Data.java & DataRecordImpl.java returns a correct list of records from the db file. So, I assume
something wrong must have happened when the list is being transfered from the server to the client through localhost.
Now this problem has been robbing my previous time , and I'd like to receive assistance from fellow SCJD-ers.
Thanks for the reply and the welcome message K. Tsang.
As for your suggestion, It is not necessary for us to explicitly serialize the remote object. The reason is because the remote object, by default implement serializable. So, as long as your remote class
extends either java.rmi.Activable or java.rmi.UniCastRemoteObject, then the return values of all methods declared in the remote class will be serialized when it travels across the wire.
However, my value object does implement Serializable.
For now, I'll dig further to find out whats wrong with my program.
And for your endeavor to finish the RMI implementation, I hope you won't experience the same problem like the one I'm facing at the moment.