Quantcast

graph object instantiation.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

graph object instantiation.

Balaji Iyengar
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: graph object instantiation.

Balaji Iyengar
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
<[hidden email]> 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:[hidden email]]
> Sent: March 8, 2005 8:19 AM
> To: [hidden email]
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jgrapht-users
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: graph object instantiation.

Balaji Iyengar
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 <[hidden email]> 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
> <[hidden email]> 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:[hidden email]]
> > Sent: March 8, 2005 8:19 AM
> > To: [hidden email]
> > 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
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/jgrapht-users
> >
>


Loading...