照著例子居然出錯--關於JbossIDE開發J2EE

diego-liu發表於2006-05-23
下面的程式碼是banq的一篇文章裡提到的一個tutorial.我照著做,報錯

public class ComputeServlet extends HttpServlet {
private FiboHome home;

public ComputeServlet() {
super();
// TODO Auto-generated constructor stub
}

public void init(ServletConfig config) throws ServletException {
try {
Context context = new InitialContext();
Object ref = context.lookup("java:/comp/env/ejb/Fibo");
home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class);
} catch (Exception e) {
throw new ServletException("Lookup of java:/comp/env/ failed");
}
}


protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException {
// TODO Auto-generated method stub
}

}

其中這條語句:
home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class);
報錯,錯誤為: cannot make a static reference to non-static method narrow(....

相關文章