照着例子居然出错--关于JbossIDE开发J2EE

06-05-23 diego-liu
下面的代码是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(....

diego-liu
2006-05-23 16:26
刚准备学J2EE,大家给点帮助.

banq
2006-05-23 16:52

>cannot make a static reference to non-static method narrow

你将一个静态引用指向了一个非静态方法。

静态归静态用;非静态归非静态

diego-liu
2006-05-23 17:06
private FiboHome home ;

声明的是一个静态变量吗

不是很懂啊,jboss官方网站的例子为什么这样的错呢?

zhuam
2006-05-24 17:55
说句真心话,各位还是要好好的学习一下 计算机基本功、Java 基本功,然后再去学习一下OO ,这样以后学习任何东东都是比较快的了,最近面试了很多Java 程序员,真让人遗憾了...

zhuam
2006-05-24 17:57
cannot make a static reference to non-static method narrow 都已经给你做解答了....

cyfu
2006-06-08 21:50
检查一下你用了那个PortableRemoteObject。

//import com.sun.corba.se.impl.javax.rmi.PortableRemoteObject;

import javax.rmi.PortableRemoteObject;

猜你喜欢