File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Problem with RMI - encountering null value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Problem with RMI - encountering null value " Watch "Problem with RMI - encountering null value " New topic

Problem with RMI - encountering null value

Yudiman Kwanmas

Joined: Feb 01, 2009
Posts: 13
Hello everyone,

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 For additional information, this method also declared and defined in the class Data in that implements the DB interface.

2. The class DataRemoteImpl in 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 & 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.
K. Tsang

Joined: Sep 13, 2007
Posts: 3132

Welcome to the Ranch.

It's hard to say from your given code what went wrong or what variable is null. A printstack is helpful identifying the filename and line number.

Personally I'm just starting RMI stuff myself so if you think it's the transmission from server to client is a problem then maybe serializing the object may help.

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Yudiman Kwanmas

Joined: Feb 01, 2009
Posts: 13
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.
I agree. Here's the link:
subject: Problem with RMI - encountering null value
It's not a secret anymore!