#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    4
    Rep Power
    0

    JSP session bean call error


    Hi,

    I am new to developing in J2EE and I am currently using JDeveloper 10g to create a shopping cart. I am having problems calling the addItem method from my JSP page. I receive the following error message:

    Error(18,10): method addItem(java.lang.Integer) not found in interface businessLayer.cartBean

    This is my session bean:
    Code:
    package businessLayer;
    
    import businessLayer.ItemException;
    
    import java.util.Vector;
    
    import javax.ejb.CreateException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    
    public class cartBeanBean implements SessionBean  
    {
      private SessionContext context;
      Vector contents;
    
      public void ejbCreate()
      {
         Vector contents = new Vector();
      }
      
      public void ejbActivate()
      {
      }
    
      public void ejbPassivate()
      {
      }
    
      public void ejbRemove()
      {
      }
    
      public void setSessionContext(SessionContext ctx)
      {
        this.context = ctx;
      }
      
      public void addItem(String itemID)
      {
        contents.add(itemID);
      }
      
      public void removeItem(Integer itemID) throws ItemException
      {
        boolean result = contents.remove(itemID);
        if (result == false)
          throw new ItemException("Item with the ID of "+itemID+" is not on the list");
      }
      
      public Vector getContents()
      {
        return contents;
      }
    }
    This is part of my JSP page:
    Code:
    <%@ page import="java.util.Vector, javax.naming.*, javax.rmi.*, businessLayer.cartBeanHome, businessLayer.cartBean"%>
    <%! 
    //declare a "global" reference to an instance of the home interface of the session bean
    public void jspInit() { 
      //obtain an instance of the home interface
      try {
        InitialContext ic = new InitialContext();
        Object objRef = ic.lookup("cartBean");
        cartBeanHome home = (cartBeanHome)PortableRemoteObject.narrow(objRef,cartBeanHome.class);
        cartBean cart = home.create();
        int one = 1;
        Integer oneI = new Integer(one);
        cart.addItem(oneI);
      }
      catch (Exception ex){
        System.err.println("Caught an unexpected exception: " + ex.getMessage());
        System.exit(1);
      } 
    }
    %>
    Thank you for your time. Any help would be most grateful.
  2. #2
  3. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    376
    The addItem() method in your bean takes a String as argument and you're trying to pass an Integer.

    Comments on this post

    • Annie79 agrees

IMN logo majestic logo threadwatch logo seochat tools logo