Why does declaring an object in a different way gives NullPointerException error in java?

Viewed 30

Hey everyone this is my first question here so there might be some newbie error in making the question comprehensible however I have tried my best to make it as clear as possible. Here we go..

Declaring an object in this way doesn't give the above mentioned error

(i.e. Like thisclassName object=new className(); n objects in this manner and having their array)

While when I declare these objects by directly creating an array of objects(in this way className object[]=new className[3]; ) it gives errorline: Exception in thread "main" java.lang.NullPointerException: Cannot assign field "id" because "<local1>[<local3>]" is null at test.main(test.java:14) See pic

0 Answers
Related