Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem with RMI - encountering null value

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 3648
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Yudiman Kwanmas
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic