Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hashtable's java. lang. NullPointerException

 
simplex du
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my code,a shopcart bean example;
import java.util.*;
public class shopCart
{
private Hashtable hashCart;
public void shopCart()
{
try
{
hashCart = new Hashtable();
System.out.println("initializing....");
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public void insCartItem(String merchNo,int merchNum)//
{
System.out.println("yaya");
try
{
hashCart.put("merchNo"+merchNo,merchNo);
hashCart.put("merchNum"+merchNo,new Integer(merchNum));
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
i use this bean in a jsp file.
Hashtable shopBean=new shopCart();
shopBean.insCartItem("12345678",2)
then show me the Exception --java.lang.NullPointerException
 
Nandkishore Dhilde
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In jsp using usebean u create instance of shopcart
<jsp:useBean id = "shopBean" class="shopCart" />
then use like this
shopBean.insCartItem("12345678",2);
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question in multiple forums, we just end up having the same conversation multiple times.
This question is covered in the JiG (intermediate) Forum here
Dave
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
read my reply at the original post page...
here
-maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic