Ernest,
Thanks for the help. I must admit that I am still a little in the dark (no surprise there).
myVar is not static. It is passed from another class. When I tried creating classes without myVar in main, I got constructor errors in the compiler. Granted that I only have a main in order to compile and run each class on its own just so that I can make sure that I have no syntax errors. In this example, I do have a couple. I would have to have
String myVar declared in main as well in order for the compiler not to throw an error when I try to javac the file. I also should have written new MyClass(String myVar) and then public MyClass(String myVar) where myVar is created and initialized in some other class which calls this constructor. That is only learned from having tried it the other way.
public SomeOtherClass {
String myVar = "The value";//here it is initialized
MyClass passMyVar = new MyClass(myVar);//here it passes fine.
}//close class
public MyClass{
String myVar;
public MyClass(String myVar) {
//myVar is intialized here but not in inner class. But, if I pass it here it is fine.
MyOtherClass passMyVarAgain = new MyOtherClass();
passMyVarAgain.getReturnValue(myVar) //passes fine with the value that I expect it to have.
}//close constructor
private ActionListener {
public method {
MyOtherClass passMyVarAgain = new MyOtherClass();
passMyVarAgain.getReturnValue(myVar); //myVar is now null. But, if not declared as an instance variable for the class, I get a compiler error.
}//close method
}//close inner class
}//close class
Does that make some sense? I know, I can see you laughing...
All of this is due to my inexperience and learning on the fly I am very sure. myVar actually gets initialized in another class where it is returned and then passed to this class. So, I thought that myVar is automatically assigned the value that is returned from the other class. Now I want to pass that value to yet another object in order for that object to do what it does. Do I need to initialize another variable in the constructor and then pass that variable? Something like String myOtherVar = myVar (I gather from your response that this is not right either)? Or is there some other way that I need to go about it?
Thanks for your help, Ernest. I am sure that I will get this with a little more help. Most of the items that you have helped me with I have learned quickly but this one is giving me a little more trouble.
All the best,
Al