Posted By:
ASHAKIRAN_JAIN
Posted On:
Friday, October 5, 2001 11:44 PM
When I run My Server program in JavaIDL, rebind method is throwing an Null Pointer Exception. As well as in the Client Program, in the resolve and narrow method also throwing NullPointerException. I checked for all objects, no one is pointing(refering) to null. I am using tnameServer. The source code is pasted down, Please get me correct code for that. Thanks, bye, Ashakiran //////////////////// HelloServant.java /////////////////// import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; class HelloServant extends _
More>>
When I run My Server program in JavaIDL,
rebind method is throwing an Null Pointer Exception.
As well as in the Client Program,
in the resolve and narrow method also
throwing NullPointerException.
I checked for all objects, no one is
pointing(refering) to null.
I am using tnameServer.
The source code is pasted down, Please
get me correct code for that.
Thanks,
bye,
Ashakiran
////////////////////
HelloServant.java
///////////////////
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
class HelloServant extends _HelloImplBase{
public String sayHello(){
return "
Hello world ! !
";
}
}
/////////////////
HelloServer.java
///////////////////
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class HelloServer{
public static void main(String args[]){
NamingContext ncRef=null;
//initialiing ORB
ORB orb = ORB.init(args, null);
if(orb == null)
System.out.println("orb not initialised");
else
System.out.println("orb initialised");
//create an servant instance, ie. impl
HelloServant helloRef = new HelloServant();
if(helloRef == null)
System.out.println("helloRef not initialised");
else
System.out.println("helloRef initialised");
//connects the servant to the ORB
orb.connect(helloRef);
try{
//obtain reference to the nameservice
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
if(objRef == null)
System.out.println("objRef not initialised");
else
System.out.println("objRef initialised");
try{
ncRef = NamingContextHelper.narrow(objRef);
if(ncRef == null)
System.out.println("ncRef not initialised");
else
System.out.println("ncRef initialised");
}catch(Exception e){
System.out.println("ERROR: " +e);
//e.printStackTrace();
}
NameComponent nc = new NameComponent("Hello","");
NameComponent path[] =new NameComponent[1];
path[0]=nc;
/**try{
ncRef.destroy();
}catch(Exception e){
System.out.println("Problem in destroy :"+e);
// e.printStackTrace();
}
*/
try{
ncRef.rebind(path,helloRef);
}catch(Exception e){
System.out.println("Problem in Rebind :"+e);
// e.printStackTrace();
}
java.lang.Object sync = new java.lang.Object();
synchronized(sync){
sync.wait();
}
}catch(Exception e){
System.out.println("Exception :"+e);
//e.printStackTrace();
}
}
}
//////////////////
HelloClient.java
/////////////////
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class HelloClient
{
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
if(objRef == null)
System.out.println("objRef not initialised");
else
System.out.println("objRef initialised");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
if(ncRef == null)
System.out.println("ncRef not initialised");
else
System.out.println("ncRef initialised");
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello","");
NameComponent path[] = {nc};
Hello helloRef = null;
try{
helloRef = HelloHelper.narrow(ncRef.resolve(path));
if(helloRef == null)
System.out.println("helloRef not initialised");
else
System.out.println("helloRef initialised");
}
catch(Exception se){
//se.printStackTrace();
System.out.println("Problem in resolve :"+se);
}
// call the method and print results
String hello = helloRef.sayHello();
System.out.println(hello);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}
<<Less