aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI help please" Watch "RMI help please" New topic
Author

RMI help please

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
My PC having had a fatal crash, I've transferred my working code to a new PC, but the RMI part doesn't work anymore.
i.e a NullPointerException is returned by the stub

Breakpoint reached at line 41 in class suncertify.client.Client by thread main.
Breakpoint reached at line 162 in class suncertify.client.FlightsAccessProxy by thread main.
Breakpoint reached at line 26 in class suncertify.clientRemoteService.RemoteDataFactory by thread main.
Breakpoint reached at line 50 in class suncertify.clientRemoteService.RemoteDataFactory by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.transport.StreamRemoteCall by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.transport.StreamRemoteCall by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.server.UnicastRef by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.server.UnicastRef by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.server.UnicastRef by thread main.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.server.UnicastRef by thread main.
Exception java.lang.NullPointerException reached at line ? in class suncertify.serverRemoteService.FlightsImpl_Stub by thread main.
Exception java.lang.NullPointerException reached at line ? in class suncertify.serverRemoteService.FlightsImpl_Stub by thread main.
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
There are too few informations to understand what's happening...
Try to recompile and redeploy entirely your code (generate RMI code again)...


Regards,<br />Andrea<br /> <br /><a href="http://www.linkedin.com/in/andreagazzarini" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID : a.gazzarini@gmail.com<br /><a href="http://www.andreagazzarini.blogspot.com" target="_blank" rel="nofollow">My Blog</a>
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

HS, I am getting the same thing with my Beta submission, and still haven't found a solution. Some say to make sure that if you are using 1.4 that the first JRE in your system path is the 1.4 version and not any older versions. If that is the case to change the order in your path to first have the 1.4 version. Delete all your .class files, recompile, then redo rmic.
Now I had tried that on mine and it didn't fix it, but it might in your case.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Mark, I have done as you recommended but with no success either.
I am using the j2sdk1.4.0_01 version of the SDK which I understood was a production version.
I hope so as I am basing my SCJD assignment on this version.
Please post the solution when you have found it.
Thanks
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
HS,
Myself and the other java ranchers will be happy to help you out with your RMI problem, but we need more information.
Please provide us with your RMI classes, such as what class you are binding to the RMI namespace, how your client is implemented, etc.
Don't post all your code, just the heirarchy of the interfaces/implentations, the 3 lines of server code that binds the object, and the 2 lines of code used on the client.
--Dave.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Sure,
I have only one interface, RemoteFlights.
On the client , a Factory class has the following code which returns a remote object. In this case a Flights object.
rd = (RemoteFlights) Naming.lookup(name);
The above code is invoked from a Proxy/Facade , again on the client if it is a remote call.
e.g. public Object[] getOriginAirports(boolean remote) throws RemoteException ,IOException, Exception,DatabaseException{
if (!(remote)) {
setDataInstance();
return data.getOriginAirports(context);
} else { return RemoteDataFactory.getData(host).getOriginAirports(context);}
}
On the server
class FlightsImpl extends java.rmi.server.UnicastRemoteObject implements RemoteFlights and has a method registerToRegistry which calls Naming.rebind(name, obj)
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
I don't see any obvious errors with the RMI code you explained. Where is the NullPointerException being thrown from? During my testing, I got a NullPointerException that turned out to have nothing to do with RMI (my remote method was invoking methods on null, woops!).
Put some break points in your client and server portions, and determine where it is happening. Then, if the problem is not obvious, post the line of code that throws the exception and perhaps one of the ranchers will know...
Good luck!
--Dave.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
I generally use the Forte IDE but I'm getting the same error when running from the Command Prompt.
I've just been uninstalling and re-installing the different versions of j2sdk 1.4.
I'm currently on j2sdk1.4.1_01.
C:\j2sdk1.4.1_01\jre\..\bin\java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=prefered-w77hl2:1337,
suspend=y -Djava.compiler=NONE "-Xbootclasspath:C:\j2sdk1.4.1_01\jre\..\lib\tools.jar;C:\j2sdk1.4.1_01\jre\lib\rt.jar;C:\j2sdk1.4.1_01
\jre\lib\i18n.jar;C:\j2sdk1.4.1_01\jre\lib\sunrsasign.jar;C:\j2sdk1.4.1_01\jre\lib\jsse.jar;C:\j2sdk1.4.1_01
\jre\lib\jce.jar;C:\j2sdk1.4.1_01\jre\lib\charsets.jar;C:\j2sdk1.4.1_01
\jre\classes;;C:\j2sdk1.4.1_01
\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.1_01\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.1_01\jre\lib\ext\localedata.jar;C:\j2sdk1.4.1_01
\jre\lib\ext\sunjce_provider.jar;C:\j2sdk1.4.1_01\jre\lib\ext\FB Nserver.jar;C:\j2sdk1.4.1_01\jre\lib\ext\FBNclient.jar" -classpath "C:\ide-userdir\system;C:\ide-
userdir\system;C:\forte4j\system;C:\forte4j\modules\ext\j2ee-1.3.jar;C:\forte4j\modules\ext\jaas-
1.0.jar;C:\forte4j\modules\autoload\activation.jar;C:\forte4j\modules\ext\jms-
1.0.2b.jar;C:\forte4j\modules\ext\jta-spec1_0_1.jar;C:\forte4j\modules\autoload\mail.jar
;C:\forte4j\modules\ext\AbsoluteLayout.jar;C:\fort
e4j\modules\ext\sql.jar;C:\forte4j\modules\ext\row
set.jar;C:\forte4j\lib\ext\jdbc20x.zip;C:\forte4j\modules\ext\servlet-2.3.jar;C:\forte4j\modules\xmlservice s.jar;C:\forte4j\lib\ext\xerces.jar;C:\forte4j\mod
ules\ext\servlet-2.2.jar;C:\forte4j\lib\ext\parser.jar;C:\forte4j\modules\schema2beans.jar;C:\forte4j\modules\soap.jar;C:\forte4j\modules\ksoap.jar;C:\ide-userdir\sampledir;C:\forte4j\beans\TimerBean.jar;C:\ide-userdir\tomcat401_base;C:\export;C:\j2sdk1.4.1_01\src.zip" -Djava.security.policy=http://62.30.122.91:8082/repository/RMI/rmi.policy -Djava.rmi.server.codebase=http://62.30.122.91:8082/repository/ -Djava.rmi.server.hostname=62.30.122.91 suncertify.client.Client "prefered-w77hl2/62.30.122.91"
Thread main stopped at suncertify.client.Client.main line 22.
Breakpoint reached at line 159 in class suncertify.client.FlightsAccessProxy by thread main.
Thread main stopped at suncertify.client.FlightsAccessProxy.getOriginAirports line 162.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 23.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 26.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 27.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 33.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 36.
Thread main stopped at suncertify.clientRemoteService.RemoteDataFactory.getData line 53.
Thread main stopped at suncertify.client.FlightsAccessProxy.getOriginAirports line 162.
Thread main stopped at java.util.logging.Logger.isLoggable line 1099.
Thread main stopped at java.util.logging.Logger.isLoggable line 1100.
Thread main stopped at sun.rmi.runtime.Log$LoggerLog.isLoggable line 206 - unavailable source file.
Thread main stopped at sun.rmi.server.UnicastRef.invoke line 93 - unavailable source file.
Thread main stopped at sun.rmi.server.UnicastRef.invoke line 97 - unavailable source file.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.transport.StreamRemoteCall by thread main.
Thread main stopped at sun.rmi.server.UnicastRef.invoke line 193 - unavailable source file.
Thread main stopped at sun.rmi.server.UnicastRef.invoke line 198 - unavailable source file.
Exception java.lang.NullPointerException reached at line ? in class sun.rmi.server.UnicastRef by thread main.
sun.rmi.transport.StreamRemoteCall seems to be the first place where a NullPointerException is thrown
[ November 10, 2002: Message edited by: Mark Spritzler ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

HS I tried to edit your post so that the [CODE] tag was areound it so it didn't change the landscape of the thread. However, It was unsuccessful
When you post Exception chains make sure you have carriage returns in there or put [CODE] tags around it to make it look nice.
Thanks
Mark
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Point taken,Mark.Now let's try this /CODE tag out.
The lines of Code executed just preceding the Exception is :

getData(host) is essentially
where RemoteFlights is an interface that extends Remote with implicit abstract methods of the Data class and a few other useful methods.
On debugging, one can see the actual reference of the rd object after the Naming lookup, though now it's treated as a FlightsImpl object.
(Luckily, as I want RMI to get at the server database methods.)
On the server , FlightsImpl extends UnicastRemoteObject implements RemoteFlights. It's implementation of
getOriginAirports is

[CODE] public Object[] getOriginAirports(String context) throws RemoteException, IOException, DatabaseException, ClassNotFoundException {
Flights flights = Database.getInstance(context);
return flights.getOriginAirports(context);
} [/CODE
Flights is an abstract of Data class. Using an AbstractFactory of flights I can get to my concrete classes of BookedFlights(customer bookings) and AvailableFlights (available seats)
and CataloguedFlights (the data given for the assignment,which I am treating as a static class stored as a Singleton).
Without going into too much detail, all this worked previously on my old machine, but feel free to comment on the design.
The NullPointerException is raised on the internals of RMI getting to the TreeSet of airports, which is a static class stored in a singleton constructed on first access to CataloguedFlights. (Probably not thread-safe yet ,but I'll come to that shortly once I pass this problemette which looks to b turning into a majorproblem).
Can anyone help with using the new 1.4 Logging features with RMI?
Thanks
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Ooops!. Must have had an extra CODE tag floating around. The last snippet should look like :

N.B. Please note that I have put a breakpoint here but have always got the Exception first.
I think enabling Logging would help .

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

HS that is exactly the same error I get, it is my first method call to a Connection class. Wait a second it might be different, your NUllPointerException happens to the object that you have in the Registry. Mine doesn't I get the Object I have in the registry and call a method on it and I get an Object back, it is a call to that Object that I get my error.
I am starting to wonder if there is an incompatibility between SDK 1.4 and maybe the Registry that is on our computer or JRE is older. I doubt it is the JRE.
I was thinking of trying to uninstall 1.4 and reinstall 1.3 and recompile, and everything else to see if it works.
Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

I have tried to revert back to 1.3 and it did not resolve this issue.
The issue must be in the ConnectionFactory, the Data interface with the Remote implementation.
The Data Interface extends Remote, the Data Remote implementation implements the Data Interface and extends UnicastRemoteObject.
But maybe when you start with one Data Interface that extends Remote, then another interface that extends this interface by adding a few more methods. Then the Data Remote implements the second interface. Thinking that we can cast or return an object of this second interface that we are going wrong.
This is a complete hypothesis.
Mark
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Yeah, I am grasping at straws at the moment.
But maybe when you start with one Data Interface that extends Remote, then another interface that extends this interface by adding a few more methods. Then the Data Remote implements the second interface. Thinking that we can cast or return an object of this second interface that we are going wrong.

Not quite with you on the above.
I have only one interface, RemoteFlights .
My Remote Data Factory on the client implements this interface and casts the Naming.lookup object to this interface. It knows nothing about the Server implementation other than through the interface . The latter also implements this interface, as do the abstract Flights class and the 3 concrete xxxxxFlights classes derived from it.
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
That should have been
I have only one remote interface

This does extend the Remote interface.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

HS
By running my code on a clean machine where Java had never been loaded before, my code ended up working.
It has to do with JRE incompatibilities. One thing you can try, it didn't help my machine, but it makes some sense. I might have needed to reboot in this case but I didn't try that.
In the Control Panel run the Java Plug-in, in the advanced tab you will be able to select the jre that it uses.
So first try it on a clean machine and see if your code works.
Mark
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Thanks for the suggestion,Mark.
I am glad you ,at least, are out of the deep end.
I'll have to beg the loan of another machine in the meantime as I can't afford another new one just yet.
What version of jdk1.4 were you using ,just out of interest?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

like 1.4_02. I think.
Mark
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
hi HS,
The NullPointerException is raised on the internals of RMI getting to the TreeSet of airports

somewhere above in the TreeSet, you are trying to get a object which is not there in the tree set and you are operating on this null object.put a try and catch around this tree set code and throw a printStackTrace on the server side,hope this solve your problem
harcharan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI help please