What is the problem of following code:
public void st(){
String[] a=null;
String a1="Hello....";
for(int i=0;i<5;i++){
a[i]=a1;
System.out.println(a[i]);
}
}
error:
Exception in thread "main" java.lang.NullPointerException
Printable View
What is the problem of following code:
public void st(){
String[] a=null;
String a1="Hello....";
for(int i=0;i<5;i++){
a[i]=a1;
System.out.println(a[i]);
}
}
error:
Exception in thread "main" java.lang.NullPointerException
Your variable named a is null, so you can't dereference it. Yet you try to dereference it by using the index[] operator on it. Take a look at the tutorials to see how to initialize an array.