客户端调用实体bean的指针为空,可能因为你没有在客户端执行create()或bean本身有错误

解决方案 »

  1.   

    你有没有在服务器端的EJB编写的时候加入异常操作啊,另外就是Bean不能使用线程或者线程API
      

  2.   

    谢谢大家,客户端代码如下:private void myInit() throws Exception {
        try {
          Context context=new InitialContext();
          home=(SessionStudentHome)PortableRemoteObject.narrow(context.lookup("SessionStudent"),SessionStudentHome.class);
          session=(SessionStudent)home.create();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }    try{
          jTModel.addColumn("学号");
          jTModel.addColumn("姓名");
          jTModel.addColumn("班级");
          session=(SessionStudent)home.create();
          ArrayList alt=session.findStudentC();//执行到此处出错,些方法为SessionBean中调用EntityBean的方法。
    }
      

  3.   

    to blueye11(流浪的我) ,加入了异常操作代码的。还有,我就是在SessionBean中调用EntityBean的findByPrimaryKey()也是如此。
      

  4.   

    SessionBean中的关键代码如下:
    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
        try{
          Context context = new InitialContext();
          System.out.println("aa");
          this.studenthome=(StudentHome)context.lookup("java:comp/env/ejb/Student");
          System.out.println("bb");
        }
        catch (Exception ex) {
          System.out.println("cc");
          throw new EJBException(ex);
        }
      }结果是输出cc,看来是 this.studenthome=(StudentHome)context.lookup("java:comp/env/ejb/Student");这句没通过,其中Student是实体Bean的名字,这样写对不对啊。请各位大侠赐教。
      

  5.   

    楼上的兄弟,要是输出结果为: 
    aa
    cc
    我才能完全相信你说的话,应该是
    this.studenthome=(StudentHome)context.lookup("java:comp/env/ejb/Student");
    出错了。但是我想你能否告诉我你的entitybean是否为local接口的?
    要是的话,我看这样可否:
    Context context = new InitialContext();
    System.out.println("aa");
    this.studentHome = (Student)context.lookup("Student");
    System.out.println("bb");