I am getting NoInitialContextException in my sample program
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kothandapani_rajakanthan
Posted On:   Friday, January 11, 2002 04:30 AM

I am getting NoInitialContextException in my sample program .what steps should i do to avoid this...... Below is the sample code..... import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.Hashtable; class Lookup { public static void main(String[] args) { // Check that user has supplied name of file to lookup if (args.length != 1) { System.err.println("usage: java Lookup "); System.exit(-1); } String name = args[0]; // Identify service provider to use Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY,    More>>

I am getting NoInitialContextException in my sample program .what steps should i do to avoid this......

Below is the sample code.....



import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;

class Lookup {
public static void main(String[] args) {
// Check that user has supplied name of file to lookup
if (args.length != 1) {
System.err.println("usage: java Lookup ");
System.exit(-1);
}

String name = args[0];

// Identify service provider to use
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");

try {
System.out.println("hello");
// Create the initial context
Context ctx = new InitialContext(env);
System.out.println("hello");
// Look up an object
Object obj = ctx.lookup(name);

// Print it out
System.out.println(name + " is bound to: " + obj);

// Close the context when we're done
ctx.close();
} catch (NamingException e) {
System.err.println("Problem looking up " + name + ": " + e);
}
}
}

   <<Less

Re: I am getting NoInitialContextException in my sample program

Posted By:   Christopher_Schultz  
Posted On:   Friday, January 11, 2002 05:49 AM

Is the file jndi.properties in your CLASSPATH? Has it been set up correctly to point to your JNDI server? (Do you haev a JNDI server set up and running?). If not, you won't be able to get an InitialContext, or anything else for that matter.



-chris
About | Sitemap | Contact