im having problem setting values into a String array.. it must be with a setter method (yes this is homework).
i have created a Person class which u can set name, age, gender and then i created a Teacher class which extends person and further allows you to set ( school teaching at, teacher ID, subjects teaching )
subjects teaching must be a String Array.
this is my setter method:
- subjectsTaught is my array declared at the begining
public void setSubTaught(int pos, String value)
{
subjectsTaught[pos]=value;
}
this is my getter method:
public String getSubTaught()
{
String sub = Arrays.toString(subjectsTaught);
int len = sub.length();
String fix = sub.substring(1,len-1);
return fix;
}
this is in my main method:
Teacher teach = new Teacher("John Smith");
teach.setSubTaught(0, "TESTTT");
I try to display it using System.out.println(teach.getSubTaught())
but I keep getting a NullPointerException returning me to the setter method at the line:
subjectsTaught[pos]=value;
what am i doing wrong :S