Getting NullPointerException as Delegator is NULL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting NullPointerException as Delegator is NULL

jillas
Hi

    I have inserted one record in the tabe and trying to retreive the rows from the table. While retreving the table rows getting the following is the code and the error we faced is getting NullPointerException as Delegator is NULL, we want to run this program from standalone system.

import org.ofbiz.entity.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.GenericDelegator.*;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityFunction;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.util.EntityUtil;
import java.util.*;
import java.util.Enumeration;
import java.util.Iterator;

public class ViewPlanet  {
         
         public static void main(String[] args)
        {
                GenericDelegator delegator=null;
                List data=null;
                try
                {
                        EntityExpr exp = EntityCondition.makeCondition("planetId",EntityOperator.EQUALS,"EARTH");
                         data = (List)delegator.findList("Planet",exp , null , null ,null , true );
                         
                         String result=null;
                         for (int i = 0; i < data.size(); i++) {
                                 result = (String) data.get ;
                            System.out.println("List Data Result = " + result);
                        }

                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }
                System.out.println("Hello World!");
                ViewPlanet vplanet = new ViewPlanet();
               
        }
}

Thanks & Regards
Prashanth Jilla
Reply | Threaded
Open this post in threaded view
|

Re: Getting NullPointerException as Delegator is NULL

BJ Freeman
look in the code for using the default delegator.
lots of examples.

jillas sent the following on 6/12/2009 3:34 AM:

> Hi
>
>     I have inserted one record in the tabe and trying to retreive the rows
> from the table. While retreving the table rows getting the following is the
> code and the error we faced is getting NullPointerException as Delegator is
> NULL, we want to run this program from standalone system.
>
> import org.ofbiz.entity.*;
> import org.ofbiz.entity.condition.*;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.GenericDelegator.*;
> import org.ofbiz.entity.GenericEntityException;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.condition.EntityCondition;
> import org.ofbiz.entity.condition.EntityFunction;
> import org.ofbiz.entity.condition.EntityOperator;
> import org.ofbiz.entity.model.ModelEntity;
> import org.ofbiz.entity.util.EntityUtil;
> import java.util.*;
> import java.util.Enumeration;
> import java.util.Iterator;
>
> public class ViewPlanet  {
>
> public static void main(String[] args)
> {
> GenericDelegator delegator=null;
> List data=null;
> try
> {
> EntityExpr exp =
> EntityCondition.makeCondition("planetId",EntityOperator.EQUALS,"EARTH");
> data = (List)delegator.findList("Planet",exp , null , null ,null , true
> );
>
> String result=null;
> for (int i = 0; i < data.size(); i++) {
> result = (String) data.get ;
>            System.out.println("List Data Result = " + result);
>        }
>
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> System.out.println("Hello World!");
> ViewPlanet vplanet = new ViewPlanet();
>
> }
> }
>
> Thanks & Regards
> Prashanth Jilla

--
BJ Freeman
http://www.businessesnetwork.com/automation
http://bjfreeman.elance.com
http://www.linkedin.com/profile?viewProfile=&key=1237480&locale=en_US&trk=tab_pro
Systems Integrator.

Reply | Threaded
Open this post in threaded view
|

Re: Getting NullPointerException as Delegator is NULL

Ashish Vijaywargiya-5
In reply to this post by jillas
Here you are assigning null value to GenericDelegator object and then
you are trying to fetch the values using null.

Please try following line to get "default" delegator object:
GenericDelegator delegator = GenericDelegator.getGenericDelegator(null);

--
Ashish


jillas wrote:

> Hi
>
>     I have inserted one record in the tabe and trying to retreive the rows
> from the table. While retreving the table rows getting the following is the
> code and the error we faced is getting NullPointerException as Delegator is
> NULL, we want to run this program from standalone system.
>
> import org.ofbiz.entity.*;
> import org.ofbiz.entity.condition.*;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.GenericDelegator.*;
> import org.ofbiz.entity.GenericEntityException;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.condition.EntityCondition;
> import org.ofbiz.entity.condition.EntityFunction;
> import org.ofbiz.entity.condition.EntityOperator;
> import org.ofbiz.entity.model.ModelEntity;
> import org.ofbiz.entity.util.EntityUtil;
> import java.util.*;
> import java.util.Enumeration;
> import java.util.Iterator;
>
> public class ViewPlanet  {
>
> public static void main(String[] args)
> {
> GenericDelegator delegator=null;
> List data=null;
> try
> {
> EntityExpr exp =
> EntityCondition.makeCondition("planetId",EntityOperator.EQUALS,"EARTH");
> data = (List)delegator.findList("Planet",exp , null , null ,null , true
> );
>
> String result=null;
> for (int i = 0; i < data.size(); i++) {
> result = (String) data.get ;
>            System.out.println("List Data Result = " + result);
>        }
>
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> System.out.println("Hello World!");
> ViewPlanet vplanet = new ViewPlanet();
>
> }
> }
>
> Thanks & Regards
> Prashanth Jilla
>  

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting NullPointerException as Delegator is NULL

jillas
Hi Ashish

           After doing the change as you specified, getting the error as following:

Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.ofbiz.base.util.Debug.<clinit>(Debug.java:86)
        at org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:129)
        at org.ofbiz.party.party.ViewPlanet.main(ViewPlanet.java:25)
Caused by: java.util.MissingResourceException: Can't find bundle for base name cache, locale en_US
        at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
        at java.util.ResourceBundle.getBundleImpl(Unknown Source)
        at java.util.ResourceBundle.getBundle(Unknown Source)
        at org.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:216)
        at org.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:212)
        at org.ofbiz.base.util.cache.UtilCache.<init>(UtilCache.java:171)
        at org.ofbiz.base.util.UtilProperties.<clinit>(UtilProperties.java:68)
        ... 3 more


Ashish Vijaywargiya-5 wrote
Here you are assigning null value to GenericDelegator object and then
you are trying to fetch the values using null.

Please try following line to get "default" delegator object:
GenericDelegator delegator = GenericDelegator.getGenericDelegator(null);

--
Ashish


jillas wrote:
> Hi
>
>     I have inserted one record in the tabe and trying to retreive the rows
> from the table. While retreving the table rows getting the following is the
> code and the error we faced is getting NullPointerException as Delegator is
> NULL, we want to run this program from standalone system.
>
> import org.ofbiz.entity.*;
> import org.ofbiz.entity.condition.*;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.GenericDelegator.*;
> import org.ofbiz.entity.GenericEntityException;
> import org.ofbiz.entity.GenericValue;
> import org.ofbiz.entity.condition.EntityCondition;
> import org.ofbiz.entity.condition.EntityFunction;
> import org.ofbiz.entity.condition.EntityOperator;
> import org.ofbiz.entity.model.ModelEntity;
> import org.ofbiz.entity.util.EntityUtil;
> import java.util.*;
> import java.util.Enumeration;
> import java.util.Iterator;
>
> public class ViewPlanet  {
>
> public static void main(String[] args)
> {
> GenericDelegator delegator=null;
> List data=null;
> try
> {
> EntityExpr exp =
> EntityCondition.makeCondition("planetId",EntityOperator.EQUALS,"EARTH");
> data = (List)delegator.findList("Planet",exp , null , null ,null , true
> );
>
> String result=null;
> for (int i = 0; i < data.size(); i++) {
> result = (String) data.get ;
>            System.out.println("List Data Result = " + result);
>        }
>
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> System.out.println("Hello World!");
> ViewPlanet vplanet = new ViewPlanet();
>
> }
> }
>
> Thanks & Regards
> Prashanth Jilla
>  

 
Reply | Threaded
Open this post in threaded view
|

Re: Getting NullPointerException as Delegator is NULL

BJ Freeman
In reply to this post by Ashish Vijaywargiya-5
a delegator is the way to communicate with the stored data.
therefore it can not be null.
it must be, what is defined in the entityengine.xml, or in web.xml.
as a helper the web.xml defines the Default delegator that is used if no
 delegator when none is defined, when part of a webapp.
GenericDelegator.getGenericDelegator("default")
says to use the default either defined in the web.xml or in the
entityengine.xml

This shows why it is important to read up on ofbiz.




jillas sent the following on 6/12/2009 5:59 AM:

> Hi Ashish
>
>            After doing the change as you specified, getting the error as
> following:
>
> Exception in thread "main" java.lang.ExceptionInInitializerError
> at org.ofbiz.base.util.Debug.<clinit>(Debug.java:86)
> at
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:129)
> at org.ofbiz.party.party.ViewPlanet.main(ViewPlanet.java:25)
> Caused by: java.util.MissingResourceException: Can't find bundle for base
> name cache, locale en_US
> at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
> at java.util.ResourceBundle.getBundleImpl(Unknown Source)
> at java.util.ResourceBundle.getBundle(Unknown Source)
> at
> org.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:216)
> at
> org.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:212)
> at org.ofbiz.base.util.cache.UtilCache.<init>(UtilCache.java:171)
> at org.ofbiz.base.util.UtilProperties.<clinit>(UtilProperties.java:68)
> ... 3 more
>
>
>
> Ashish Vijaywargiya-5 wrote:
>> Here you are assigning null value to GenericDelegator object and then
>> you are trying to fetch the values using null.
>>
>> Please try following line to get "default" delegator object:
>> GenericDelegator delegator = GenericDelegator.getGenericDelegator(null);
>>
>> --
>> Ashish
>>
>>
>> jillas wrote:
>>> Hi
>>>
>>>     I have inserted one record in the tabe and trying to retreive the
>>> rows
>>> from the table. While retreving the table rows getting the following is
>>> the
>>> code and the error we faced is getting NullPointerException as Delegator
>>> is
>>> NULL, we want to run this program from standalone system.
>>>
>>> import org.ofbiz.entity.*;
>>> import org.ofbiz.entity.condition.*;
>>> import org.ofbiz.entity.GenericValue;
>>> import org.ofbiz.entity.GenericDelegator.*;
>>> import org.ofbiz.entity.GenericEntityException;
>>> import org.ofbiz.entity.GenericValue;
>>> import org.ofbiz.entity.condition.EntityCondition;
>>> import org.ofbiz.entity.condition.EntityFunction;
>>> import org.ofbiz.entity.condition.EntityOperator;
>>> import org.ofbiz.entity.model.ModelEntity;
>>> import org.ofbiz.entity.util.EntityUtil;
>>> import java.util.*;
>>> import java.util.Enumeration;
>>> import java.util.Iterator;
>>>
>>> public class ViewPlanet  {
>>>
>>> public static void main(String[] args)
>>> {
>>> GenericDelegator delegator=null;
>>> List data=null;
>>> try
>>> {
>>> EntityExpr exp =
>>> EntityCondition.makeCondition("planetId",EntityOperator.EQUALS,"EARTH");
>>> data = (List)delegator.findList("Planet",exp , null , null ,null ,
>>> true
>>> );
>>>
>>> String result=null;
>>> for (int i = 0; i < data.size(); i++) {
>>> result = (String) data.get ;
>>>            System.out.println("List Data Result = " + result);
>>>        }
>>>
>>> }
>>> catch (Exception e)
>>> {
>>> e.printStackTrace();
>>> }
>>> System.out.println("Hello World!");
>>> ViewPlanet vplanet = new ViewPlanet();
>>>
>>> }
>>> }
>>>
>>> Thanks & Regards
>>> Prashanth Jilla
>>>  
>>  
>>
>

--
BJ Freeman
http://www.businessesnetwork.com/automation
http://bjfreeman.elance.com
http://www.linkedin.com/profile?viewProfile=&key=1237480&locale=en_US&trk=tab_pro
Systems Integrator.