tuscany-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Kurinskas <scott.kurins...@gemstone.com>
Subject RE: java.lang.NullPointerException when trying to create an empty data graph
Date Wed, 16 Aug 2006 23:42:32 GMT

Thanks everyone!  My example is up and running.  Once I followed Kevin's
advice and tailored by example appropriately, life was good.

Regards,
Scott 

-----Original Message-----
From: kelvin goodson [mailto:kelvingoodson@gmail.com] 
Sent: Wednesday, August 16, 2006 1:43 PM
To: tuscany-user@ws.apache.org
Subject: Re: java.lang.NullPointerException when trying to create an empty
data graph

Scott,
  a couple of things ...
   there's no evidence in your test case of defining your type system.  To
create any DataObject there must be an instance of commonj.sdo.Type that is
accessible.  No DataObject can exist without a Type.  The ChangeSummary test
case you mention creates these Type instances in its setup routine with ...

    protected void setUp() throws Exception {
        super.setUp();

        // Populate the meta data for the test (Stock Quote) model
        URL url = getClass().getResource(TEST_MODEL);
        InputStream inputStream = url.openStream();
        XSDHelper.INSTANCE.define(inputStream, url.toString());
        inputStream.close();
    }

by supplying an xml schema which SDO can convert into Types.   Only after
this can  DataObjects relating to the types defined in the schema be
created.
If I understand your problem correctly you'll need to have something like
the xml schema referenced by the TEST_MODEL constant, adapted for your
needs.

also your namespace looks a bit funny in this posting,  perhaps thats your
email client trying to be clever, but " <http://www.example.com/sample>
http://www.example.com/sample";

 is not a valid namespace  -- you just need the single URL "
http://www.example.com/sample";


By the way,  programs using dynamic type definition in this way (as opposed
to generaing Java classes) do not fall foul of the current problems of SDO
initialization mentioned earlier in this thread.  It's only in some cases
using generated Java classes that we sometimes have to add the explicit call
to DataObjectUtil.initRuntime()



Regards, Kelvin.

On 16/08/06, Scott Kurinskas <scott.kurinskas@gemstone.com> wrote:
>
> Thanks Hasan.
>
> I tried this but I receive the exact same exception.  I've also tried 
> other mechanisms to initiate the SDO runtime 
> (DataObjectUtil.initRuntime();) to no avail.  I realize this has to be 
> a trivial issue, but I'm stumped.  Below is the little class I'm 
> using.
>
>
> import org.apache.tuscany.sdo.util.DataObjectUtil;
> import org.apache.tuscany.sdo.util.SDOUtil;
> import commonj.sdo.ChangeSummary;
> import commonj.sdo.DataGraph;
> import commonj.sdo.DataObject;
> import commonj.sdo.helper.DataFactory; import 
> commonj.sdo.helper.TypeHelper; import commonj.sdo.Type;
>
>
> public class SDOTest {
>
> /**
>   * @param args
>   */
> static final String CUSTOMER_NAMESPACE = " 
> <http://www.example.com/sample> http://www.example.com/sample";
>
> public static void main(String[] args) {
>   // TODO Auto-generated method stub
>   SDOUtil.createTypeHelper();
>   //DataObjectUtil.initRuntime();
>
>   try {
>
>    DataGraph  dataGraph  = SDOUtil.createDataGraph();
>    DataObject   customer  = dataGraph.createRootObject("
> <http://www.example.com/simple> http://www.example.com/simple", 
> "Customer");
>
>    if (customer == null) {
>     System.out.println("dobj is null");
>    }
>    else {
>     customer.setString("firstName", "scott");
>     System.out.println("first name = " + customer.getString("firstName"));
>    }
>
>   }
>   catch (Exception e)
>   {
>    e.printStackTrace();
>   }
>
>
> }
>
> }
>
>   _____
>
> From: Hasan Muhammad [mailto:asundar@us.ibm.com]
> Sent: Tuesday, August 15, 2006 9:23 AM
> To: tuscany-user@ws.apache.org
> Subject: Re: java.lang.NullPointerException when trying to create an 
> empty dat a graph
>
>
>
> Hi Scott,
>
> It looks like the SDO Runtime did not get initialized prior to 
> creating the DataGraph. If so, it would most likely fail to get the 
> right SDO Factory and hence could return a null object for the 
> DataGraph. Hence the NullPointerException.
>
> You could initiate the SDO Runtime simply by inserting the following 
> line in the beginning before any SDO calls..
>
> SDOUtil.createTypeHelper();
>
> regards
>
> Hasan Muhammad
>
> Allah's Messenger Muhammad (Pbuh) said, "While a man was on the way, 
> he found a thorny branch of a tree there on the way and removed it. 
> Allah thanked him for that deed and forgave him."
> Inactive hide details for Scott Kurinskas 
> <scott.kurinskas@gemstone.com>Scott Kurinskas < 
> scott.kurinskas@gemstone.com>
>
>
>
>
>
>
>         Scott Kurinskas <scott.kurinskas@gemstone.com>
>
>         08/14/2006 08:03 PM
>
>
>
>         Please respond to
> tuscany-user@ws.apache.org
>
>
>
>
> To
>
> tuscany-user@ws.apache.org
>
>
>
> cc
>
>
>
>
>
> Subject
>
> java.lang.NullPointerException when trying to create an empty dat a 
> graph
>
>
>
> Hi-
>
> I'm trying to put togther a very simple example constructing an empty 
> DataObject.  Its very similar to the ChangeSummary test case.  
> However, whenever I try to construct an empty DataObject, I receive a 
> null pointer exception.  My example is below.  Its failing on 
> 'DataObject customer ...'.
> I do not understand why this exception occurs.  Any assistance would 
> be greatly appreciated.
>
> try {
> DataGraph dataGraph = SDOUtil.createDataGraph(); DataObject customer = 
> dataGraph.createRootObject("http://www.example.com/simple
> <http://www.example.com/simple> ", "Customer"); ...
>
>
> Exception:
>
> java.lang.NullPointerException
> at org.eclipse.emf.ecore.util.EcoreUtil.create(EcoreUtil.java:2918)
> at
> org.apache.tuscany.sdo.util.DataObjectUtil.create(DataObjectUtil.java
> :2324)
> at
> org.apache.tuscany.sdo.impl.DataGraphImpl.createRootObject(
> DataGraphImpl.jav
> a:594)
> at gemfire.example.customer.sdo.SDOTest.main(SDOTest.java:21)
>
>
> Regards,
> Scptt
>
>
>
>
>


--
Best Regards
Kelvin Goodson

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message