AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Newbie question - Need help deploying Bean

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.misc
View previous topic :: View next topic  
Author Message
keith
Guest





PostPosted: Thu Aug 14, 2003 4:50 am    Post subject: Newbie question - Need help deploying Bean Reply with quote



Hi,

I get the following error message when I try to deploy a bean from a
lesson in a book. I've searched the newsgroups, however, haven't
found the cause. Any help would be greatly appreciated.

TIA!
Keith


** Error Message **

java.lang.InstantiationException: ShoppingCart


** Here is some of the code from the jsp page that calls the bean. **

<%@ page errorPage="errorpage.jsp" %>
<%@ page import="myCart.*"%>
<jsp:useBean id="myCart" scope="session" class="ShoppingCart" />


<head> <title>DVD Catalog</title> </head>

<% String id = request.getParameter("itemId"); %>




** Here is the Java code that is being used **
package myCart;
import java.lang.String;
import java.lang.Integer;
import java.lang.Float;
import java.util.Hashtable;
import java.util.Enumeration;

public class ShoppingCart {

protected Hashtable items = new Hashtable();

public void ShoppingCart() {
}

public void addItem(String itemId, String desc, float price, int
quantity) {
String[] item = {itemId, desc, Float.toString(price),
Integer.toString(quantity)};

if (items.containsKey(itemId)) {
String[] tmpItem = (String[])items.get(itemId);
int tmpQuant = Integer.parseInt(tmpItem[3]);
quantity += tmpQuant;
tmpItem[3] = Integer.toString(quantity);
}
else {
items.put(itemId, item);
}
}

public void removeItem(String itemId) {
if (items.containsKey(itemId)) {
items.remove(itemId);
}
}

public void updateQuantity(String itemId, int quantity) {
if (items.contains(itemId)) {
String[] tmpItem = (String[])items.get(itemId);
tmpItem[3] = Integer.toString(quantity);
}
}

public Enumeration getEnumeration() {
return items.elements();
}

public float getCost() {
Enumeration enum = items.elements();
String[] tmpItem;
float totalCost = 0.00f;

while (enum.hasMoreElements()) {
tmpItem = (String[])enum.nextElement();
totalCost += (Integer.parseInt(tmpItem[3]) *
Float.parseFloat(tmpItem[2]));
}
return totalCost;
}

public int getNumOfItems() {
Enumeration enum = items.elements();
String[] tmpItem;
int numOfItems = 0;

while (enum.hasMoreElements()) {
tmpItem = (String[])enum.nextElement();
numOfItems += Integer.parseInt(tmpItem[3]);
}
return numOfItems;
}
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.