Re: [jgrapht-users] graph object instantiation.
Brought to you by:
barak_naveh,
perfecthash
From: Balaji I. <bri...@gm...> - 2005-03-08 14:38:58
|
i fixed it, I was doing this: DefaultDirectedGraph g_graph = new DefaultDirectedGraph(); in the constructor which was creating a new object rather than instantiating the class member. thanks -balaji On Tue, 8 Mar 2005 09:33:04 -0500, Balaji Iyengar <bri...@gm...> wrote: > I was just typing some sort of a psuedo code. I got those right in my > program. It looks like the reference returned by the > DefaultDirectedGraph constructor is alive only in the body of the > method it is in. So if you have this: > > protected final void sample_method(){ > DefaultDirectedGraph g_graph = new DefaultDirectedGraph(); > Integer tp_obj = new Integer(2); > g_graph.addVertex(tp_obj); > } > > then it works fine without a nullpointer exception. > > thanks > -balaji > > On Tue, 8 Mar 2005 09:07:35 -0500, Bergeron Guyard, Alexandre > <Ale...@dr...> wrote: > > Well, > > > > From the little I see, I have a few ideas: > > > > 1) In your class you declare a method addNode(), but you later call > > addVertex().... > > > > 2) You instanciate a SampleGraph under the name tmp-graph-obj, but use the > > name tmp-obj to call the addNode()/addVertex() method later on... > > > > Hope this helps. > > > > Alex > > > > -----Original Message----- > > From: Balaji Iyengar [mailto:bri...@gm...] > > Sent: March 8, 2005 8:19 AM > > To: jgr...@li... > > Subject: [jgrapht-users] graph object instantiation. > > > > Hello, > > > > I have a DefaultDirectedGraph object as a private member of a class, > > which i instantiate in the constructor of the class. I then use call > > the addVertex function later from other files in my code structure. > > This is how my class looks like: > > > > class SampleGraph { > > private DefaultDirectedGraph g_graph; > > // other members > > > > // constructor > > SampleGraph(){ > > DefaultDirectedGraph g_graph = new DefaultDirectedGraph(); > > } > > > > // wrapper method > > protected final boolean addNode(Object gnode){ > > return g_graph.addVertex(gnode); > > } > > } > > > > elsewhere in the code i do: > > > > SampleGraph tmp-graph-obj = new SampleGraph (); > > tmp-obj.addVertex(tmp-node); > > > > which should add the tmp-node to the g_graph member of tmp-graph-obj, > > is this the right way of doing this. I get a null pointer exception > > here and i cant figure what i am doing wrong here. > > Any help would be very much appreciated. > > > > thanks > > > > ------------------------------------------------------- > > SF email is sponsored by - The IT Product Guide > > Read honest & candid reviews on hundreds of IT Products from real users. > > Discover which products truly live up to the hype. Start reading now. > > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > > _______________________________________________ > > jgrapht-users mailing list > > jgr...@li... > > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > > > |