照着书上的例子竟然运行不了
照着书上的例子竟然运行不了,抛NoInitialContextException异常,是否要用到hashtable?
要怎么写呢?
import javax.naming.*;
public class JNDILookup {
public final static String JNDI="sams/book";
public static void main(String[] args) {
try{
Context ic=new InitialContext();
String name=(String)ic.lookup(JNDI);
System.out.println(JNDI+"="+name);
}catch(NamingException e){
System.err.println(e);
System.exit(1);
}catch(ClassCastException e){
System.err.println(e);
System.exit(1);
}
}
}