I have a problem in copying the data in array from object variable which is also a type String.
Can any one explain this
String[] childRoot = null;
int k = 1;
System.out.println(" Name " + d.getName());
childRoot[k]=d.getName(); *
k++;
output
Name try 1
java.lang.NullPointerException
at *
Detail for :getName
java.lang.String getName()
Returns the name of this object
Yes, you have to initialize an array before you can use it. If you don’t want to initialize, there’s an alternative way you can fill up the array like this:
I put the first element as null, because you wanted the name to be in index 1 which is the 2nd element of the array.