I've run into a situation that I don't quite understand and was hoping somebody
could help.

I have created a simple class that I'm using in my main class. I tried declaring
a global variable to this class and then instantiate it when Main is called.

package myApp;
import myApp.animal;

public class JFrame extends javax.swing.JFrame {

private animal myAnimal;

public static void main(String args[])
myAnimal = new animal();

private void jButtonMouseClicked()
myAnimal.setX(100); // generates an exception error

In the code above, if you click the button, a null exception is generated.
My guess is because the object is not being instantiated even though I do
so in "main".

If I change the declared variable to read:
private animal myAnimal = new animal();

and delete the instantiation in "main", the code works.

This is confusing to me because I thought you could declare a global class
object and instantiate it elsewhere. For example, I could set "int x;" and
then set its value in a method.

Anyone help on explaining this one is greatly appreciated. Thanks!!!!