• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Nulpointerexception in this method ......  RSS feed

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is the function returning Collection Object.
=========================

public Collection getFeaturedparts(String ftr, String groupid, String subgroupid) throws EJBException,NullPointerException,RuntimeException{
PartsData pdata=new PartsData(); //PartsData is
ValueObject Class
Collection newCol=null;

pdata.setPartid("P00001");
pdata.setDescription("Parts Desc");
pdata.setDetaildesc("DetailDesc");
pdata.setPartcategoryid("001");
pdata.setPartsubcategoryid("001");
pdata.setMoq(new Float(4));
pdata.setEoq(new Float(4));
pdata.setStockquantity(new Float(4));
pdata.setReorderlevel(new Float(4));
pdata.setUom("Kg");
pdata.setUnitweight(new Float(4));
pdata.setComposition("Comp 1");
pdata.setClassification("Locpmotive");
pdata.setNmfc("");
pdata.setLeadtime(new Timestamp(System.currentTimeMillis()));
pdata.setWeightunit("wt");
pdata.setSupplierid("S00003");
pdata.setFeatureditem("Yes");
pdata.setStatus("Active");
pdata.setPartmasterid("P000003");
pdata.setThumbnail("Thb 1");
pdata.setDrawingno("Drg 101");
pdata.setGroupid("002");
pdata.setSubgroupid("003");
pdata.setDiscount(new Float(4));
pdata.setPartmasterid("P0000531");
pdata.setListprice(new Float(4));
newCol.add(pdata); //On this line i m getting error
System.out.println("Got featured Products!!!");
System.out.println("Size of newCol="+newCol.size());
return newCol;
}
=========================

In this function 'PartsData' class is ValueObject Class. Now I m adding object of this class 'pdata' to collection object(newCol) & returning it.
But when I m accessing this method I m getting following exception.

=========================
18:28:21,737 ERROR [LogInterceptor] RuntimeException in method: public abstract java.util.Collection econify.session.parts.interfaces.PartsSession.getFeaturedparts(java.lang.String,java.lang.String,java.lang.String) throws java.lang.NullPointerException,java.lang.RuntimeException,java.rmi.RemoteException:
java.lang.NullPointerException
at econify.session.parts.ejb.PartsSessionBean.getFeaturedparts(PartsSessionBean.java:314)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)

=================

Please tell me why I am getting this method. I am getting error on line Number 314 of my Class (PartSessionBean.java) to which this function 'getFeaturedparts' belongs. Line 314 of my class is 'newCol.add(pdata);'.

I think all the things are right in above method. But why I m getting error?
Please tell me.
Thanx in advance.
Prash
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"newCol" has the value null:

Collection newCol=null;

You can't call a method on a null reference. You need to make newCol actually refer to a Collection (for instance an ArrayList

Collection newCol=new ArrayList();
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!