Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Variables trouble

 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get my variable to be set to a value during runtime and then be able to be accessed by all the class methods?
I have

The problem is I set the itemSelected value but when I come to use it in the editDefectReport method its value is null. I though setting it as a global varaible allowed all classes to access the value?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As shown, this will work as you expect; perhaps there's a bit more to the code that you're not showing us that's causing the problem.
 
Alex Cano
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>The problem is I set the itemSelected value but when I come to use it in
>the editDefectReport method its value is null. I though setting it as a
>global varaible allowed all classes to access the value?
I agree with Ernest. The code you show here should work as you expect as long as you're setting it in the same instance of the class that you're calling the editDefectReport method on (assuming something else in your code isn't setting this value to null after you set it to whatever you initially set it to). I would post the remainder of the relavent code for this.
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much, I have managed to identify the problem - I was using seperate instances - and everything is working again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic