1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Null pointer exception

Discussion in 'Java' started by bsudhir6, Sep 19, 2010.

  1. bsudhir6

    bsudhir6 New Member

    Joined:
    Apr 4, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    package Obj1_3_1_4;
    public class ArrEx
    {
        // Arrays are can be declared like this
        int[] a;
        int b[];
        int[][] c;
        int[] d[][];
        String[] S;// Array of string class objects
        public static void main(String[] args)
        {
            int i=0,j=0,k=0;
            ArrEx AE=new ArrEx();
            
            for(i=0;i<10;i++)
            {
                AE.a[i]=6;
                AE.b[i]=44;
            }
            for(i=0;i<10;i++)
            for(j=0;j<10;j++)
            AE.c[i][j]=644;
            
            for(i=0;i<10;i++)
            for(j=0;j<10;j++)
            for(k=0;k<10;k++)
            AE.d[i][j][k]=1;
            
            for(i=0;i<10;i++)
            AE.S[i]="S";
            
            for(i=0;i<10;i++)
            {
                System.out.println(AE.a[i]);
                System.out.println(AE.b[i]);
            }
            
        for(i=0;i<10;i++)
            for(j=0;j<10;j++)
            System.out.println(AE.c[i][j]);
            
            for(i=0;i<10;i++)
            for(j=0;j<10;j++)
            for(k=0;k<10;k++)
            System.out.println(AE.d[i][j][k]);
            
            for(i=0;i<10;i++)
            System.out.println(AE.S[i]);
        }
    }
    This program compiles fine and...the output while executing is
    Exception in thread "main" java.lang.NullPointerException
    at Obj1_3_1_4.ArrEx.main(ArrEx.java:20)

    Please help...
     

Share This Page