The above method is in my main class. The reference variable actorBox is static and refers to a JTextField.
The method is then used in another class, but it throws a NullPointerException. My actorBox Object is instantiated with new and works fine for other methods of the same class. Somehow the variable inside the static method points to null.
How are you ensuring the static variable is set before the static method is called?
henri henri
Ranch Hand
Joined: Oct 03, 2005
Posts: 115
posted
0
I am trying different things, but as I am a novice programmer, I am still learning from experince. I will try using abstract, but final did not work. When I use the method getText() on the actorBox reference within the same class, it works of course. I want to get the text in the TextField from the main class and use it in a secondary class. I should be able to do this with a static method.
henri henri
Ranch Hand
Joined: Oct 03, 2005
Posts: 115
posted
0
I thought about your question and I initialized the actorBox before my constructor. The NullPointerException for that method is longer there.
Nimit Muni
Greenhorn
Joined: Oct 04, 2005
Posts: 1
posted
0
Hello
Remember...static methods should always call a method which is static.
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Originally posted by Nimit Muni: Hello
Remember...static methods should always call a method which is static.
Static methods should not exist and are a defective part of the language. I think the point you're trying to make is "do not call static methods as instance methods". This includes static method calls on an implicit (or explicit) 'this' reference.