• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Instance Variables From Multiple Methods.  RSS feed

 
Jarrod Rackley
Ranch Hand
Posts: 30
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have been working on a program to use at work. In there I have instance variables which are being modified by one method and read by another. At least that is the goal.
Currently I access and modify the variable in the one method, but when I attempt to read it from another I receive what the variable contained when first instantiated.
My understanding of Java is limited and I am unsure how I should go about correcting the issue.



In the sendOnCommit() method it will get a nullpointer exception as the code is written above. I figured out why I got the NPE and changed a couple of things:



However the print will show loopStr as "Loopback IP". The problem is I do not know how to modify the variable for the whole class from that method as I cannot return anything from the focus listener.
I am not sure where to go from here or how to proceed at this point.


Thank you for any help you are willing to give.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Are you sure that generateAndPlaceComponents() is being called before sendOnCommit()? How do you know?
 
Jarrod Rackley
Ranch Hand
Posts: 30
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thank you for the quick reply.

From what I can tell, generateAndPlaceComponents() should be getting called first.



is the method that calls it. Within that method I have an ActionListener on the commit button that calls the senOnCommit() method.



I did manage to think of a solution. I created a String[] variable within the generateAndPlaceComponents() method and I passed that, containing all my variables, on to the sendOnCommit() method.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!