Java query Null Pointer Exception

Hi Team,

As discussed in the java essentials for Hadoop we can create we can create an array object while invoking the constuctor of a class as shown below:

I wanted to do the same through command line in eclipse:

Here i have create two classes MyDog.java and HelloWorld.java under the same package my project and i am trying to create the object and invoke the constructor of MyDog Class inside the main function of Hello World.java program as shown below:

MyDog Program:

\

Hello World Program:

If i try to excute the HelloWorld Program by clicking on Run Configurations in eclipse as shown below:

When i click on run its throwing me the following error:

What i fail to understand since my object dog is an array i can pass any no.of arguments through the main command line argument that is args ,so in this case i have passed two arguments to the array object it should have printed both,instead it is not able to point to the second argument and throwing null pointer exception.

I am not able to figure out what has gone wrong with my code.

Please guide.

Regards,
Anindita

Hi Team,

Please look into the the above mentioned issue.

Regards,
Anindita

Hi Team,

Please help.

Regards,
Anindita

Hi Team,

Any update on the above issue.

Regards,
Anindita

When you are not passing arguments the args.length is zero and that’s why the array allocation is throwing that error.

Please recheck if the arguments are really being passed when running. Try printing args.length for debugging it.