0

I am having a problem with a getter like :

    String[] T2;
    T2=Ti.getT();

Where getT() is :

    public class MyClass {

        public final String[] T=new String[3];

        MyClass(){

           this.T[0]="...";
           this.T[1]="...";
           this.T[2]="...";

        }

        public String[] getT() {
            return T;
        }


    }

I am getting the message java.lang.NullPointerException in the T2=Ti.getT(); line.

Can anyone give me a clue? Am I using the array correctly?

Thank you.

David K
  • 3,147
  • 2
  • 13
  • 19
AlexG
  • 11
  • 5

1 Answers1

0

Based on what you have posted; Ti is null. Make sure you declare and initialize Ti before you try and access it. You need something like

MyClass Ti = new MyClass();

and you might consider

String[] T2 = null;
if (Ti != null) {
    T2 = Ti.getT();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249