This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source 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

Referencing an object instantiated inside a method?  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all -

I'm instantiating an object inside a method like...

cInvoker = new ClickInvoker(lastOMove);

Now, cInvoker is originally declared outside the method. I'm then trying to reference the instantiated object inside a 2nd method, but I'm finding that cInvoker is null. I think it must be getting deleted once it goes out of scope or something?

Is there anyway to copy the new object so that I can reference it outside of where it was declared?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show your all code?  thanks
 
Bartender
Posts: 2277
95
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Erickson wrote:...Now, cInvoker is originally declared outside the method.


Can you elaborate what "outside" means in this context ? Share your code.

James Erickson wrote:
I'm then trying to reference the instantiated object inside a 2nd method, but I'm finding that cInvoker is null. I think it must be getting deleted once it goes out of scope or something?


If the object is the same, I don't think it should be null.

Here's a short code that changes the value of a variable across method calls:


output:
 
Marshal
Posts: 5980
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that the method where cInvoker is instantiated is not getting called before the method where you use cInvoker?  If it's declared outside of any methods, then I don't think it's going out of scope.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!