Hi all,
I have a situation that I think might be one of those things that should be obvious, but for some reason isn't clicking.
I am writing a small
Java program.
In it, I have a class that, in its instance variables, uses objects from another class, so:
public class myclass1 {
private myobject mo
where 'myobject' is an object of a type defined in a different class.
within this class there are two methods.
The first actually creates the objects:
void method1(){
myobject mo = new myobject();
}
Then the second needs to update these objects, so:
void method2(){
mo.setvariable1("randomstring");
}
However, when method2 gets called, it gives a nullPointer Exception.
I am assuming this is something to do with the fact that while the objects are declared as instance variables, their own instance variables don't exist yet, or can't be accessed or something, but I can't quite figure it out...
How could this be put together so that both method1 and method2 could access the objects in question? This seems to work when using Swing components, like if method2 were also to call a get() method on a JTextArea defined in method1 this would work, but on my own, created objects there is an error..
Apologies for the long post, appreciate any help!