Home arrow static arrow Java Programming [Archive] - Run time ERROR
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Run time ERROR
This topic has 4 replies on 1 page.

Registered: 4/29/04
Run time ERROR  
Jun 21, 2004 1:57 PM


i have the following remote method in RemoteInterface.java:

public Vector getAllOccupations() throws RemoteException;

and this is its implementation in ArchiveServer.java:

public Vector getAllOccupations(){
ResultSet rs;
String query="SELECT occupation FROM employee";
Vector v=new Vector();
boolean flag;
}catch (SQLException e) {
System.out.println(" Could not connect to the database");
return v;

and when i invoke it from the client the following error appeare when run the client:

Exception in thread "main" java.lang.NullPointerException
at ArchiveServer.getAllOccupations(ArchiveServer.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegateingMethodAccessorImple.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at sun.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at ArchiveServer_Stub.getAllOccupations(Unknown Source)
at Archive.init(Archive.java:204)
at Archive.main(Archive.java:319)

what is the problem?


Registered: 8/15/02
Re: Run time ERROR  
Jun 21, 2004 2:02 PM (reply 1 of 4)

One of two things...

1. stmt is null OR
2. the executeQuery is returning null (this is more likely)

Adding a couply of println's in should solve your problem.

Registered: 6/16/03
Re: Run time ERROR  
Jun 21, 2004 2:52 PM (reply 2 of 4)

The documentation specifies that executeQuery never returns null...

Registered: 4/30/99
Re: Run time ERROR  
Jun 21, 2004 3:15 PM (reply 3 of 4)

You know which line is "line 50" and we don't. However my guess would be that stmt is null as well. Look at line 50 and see which variables are being referenced.

Registered: 11/20/03
Re: Run time ERROR  
Jun 22, 2004 5:36 AM (reply 4 of 4)

Make sure that "stmt" has class level scope, ie an instance variable and is initialised
before "getAllOccupations()" method is called. Also, make sure that you close all the
resources properly. Like rs.close(), stmt.close(), connection.close().

Also to improve the code make sure, you don't create any primitive or class objects
within a iterative loop (unless or until required).

This topic has 4 replies on 1 page.