简单的bmp请指教错误。

yangxinfengg 2004-10-18 11:03:06
java.lang.NullPointerException: narrowFrom'null' narrowTo:'interface yang2.DeptRemoteHome'It is invalid to call narrow with null parameters

at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:94)

at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)

at yang2.DeptTestClient1.main(DeptTestClient1.java:331)-- Succeeded initializing bean access through Home interface.
这是报的错误。
bean类如下:
import javax.ejb.*;
import java.sql.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;

public class DeptBean implements EntityBean {
PreparedStatement ps;
Connection con;
EntityContext entityContext;
java.math.BigDecimal deptno;
java.lang.String dname;
java.lang.String loc;
public java.math.BigDecimal ejbCreate(java.math.BigDecimal deptno) throws CreateException {
setDeptno(deptno);
return null;
}
public void ejbPostCreate(java.math.BigDecimal deptno) throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() throws RemoveException {
/**@todo Complete this method*/
}
public void setDeptno(java.math.BigDecimal deptno) {
this.deptno = deptno;
}
public void setDname(java.lang.String dname) {
this.dname = dname;
}
public void setLoc(java.lang.String loc) {
this.loc = loc;
}
public java.math.BigDecimal getDeptno() {
return deptno;
}
public java.lang.String getDname() {
return dname;
}
public java.lang.String getLoc() {
return loc;
}
public java.math.BigDecimal ejbFindByPrimaryKey(java.math.BigDecimal deptno) throws FinderException {
System.out .println("FindByPrimaryKey begins");
try {
ps=con.prepareStatement("SELECT DEPTNO,DNAME,LOC FROM dept WHERE DEPTNO=?");
ps.setBigDecimal(1,deptno);
ResultSet rs=ps.executeQuery() ;
if(rs.next())
{
this.deptno =rs.getBigDecimal(1);
this.dname =rs.getString(2);
this.loc=rs.getString(3);
}
else{
System.out .println("find error");
}
}
catch (SQLException ex) {
throw new EJBException("Exception"+ex);
}

try {
ps.close();
}

catch (SQLException ex1) {
System.out .println("cannt"+ex1);
}
System.out .println("enc");
return deptno;
}
public void ejbLoad() {
/**@todo Complete this method*/
}
public void ejbStore() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void unsetEntityContext() {
this.entityContext = null;
}
public void setEntityContext(EntityContext entityContext) {
this.entityContext = entityContext;
try{
System.out .print("make connection");
makeConnection();
}
catch(Exception ex){
throw new EJBException("unable connection"+ex);}
}
public Connection makeConnection() {

try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jkbc/scottDataSource");
con = ds.getConnection();
return con;
}
catch (Exception ex) {
System.out .print("Exception in connection"+ex);
return null;
}
}
}
...全文
91 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangxinfengg 2004-10-19
  • 打赏
  • 举报
回复
搞定拉
serf 2004-10-18
  • 打赏
  • 举报
回复
你的是jbuilder自动生成的么?
不要这么用:deptRemoteHome=(DeptRemoteHome)PortableRemoteObject.narrow(ref,DeptRemoteHome.class);
整个类DeptTestClient1已经封装好了。create后,可以直接通过client.
DeptTest.方法 进行调用了。
serf 2004-10-18
  • 打赏
  • 举报
回复
问题是对象还没创建。main里如下修改。
DeptTestClient1 client = new DeptTestClient1();
client.create(); ///要加上这一句。
deptRemoteHome=(DeptRemoteHome)PortableRemoteObject.narrow(ref,DeptRemoteHome.class);

各位老兄不要来捡便宜哦。
yangxinfengg 2004-10-18
  • 打赏
  • 举报
回复
客户端如下:
public static void main(String[] args) throws RemoteException,
FinderException {
DeptRemoteHome deptRemoteHome;
DeptTestClient1 client = new DeptTestClient1();
deptRemoteHome=(DeptRemoteHome)PortableRemoteObject.narrow(ref,DeptRemoteHome.class);
System.out .println("find a record is 10");
DeptRemote deptRemot=deptRemoteHome.findByPrimaryKey(new BigDecimal(10));
System.out .print("get deptno"+deptRemot.getDeptno() +"name"+deptRemot.getDname() );
}
}

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧