 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
keith Guest
|
Posted: Thu Aug 14, 2003 4:50 am Post subject: Newbie question - Need help deploying Bean |
|
|
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 |
|
 |
|
|
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
|
|