Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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
 
author and iconoclast
Posts: 24203
43
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();
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!