null pointer exception from copying a growing inner array and outer array : this is my first question and I have done as much research as I can into similar questions about 2d arrays and null pointer exceptions but have not found an answer that resembles my situation.

My program is supposed to be very basic: take an input "image" file of integer values and "soften" those values by taking the average of values around each.

I'm having trouble with the initial process of copying the file into a 2 dimensional array with while loops, though the loops don't seem to be the problem as I have tried "do While" loops already.

I initially tried using Arrays.copyOf to copy the arrays but that initially gave me the NPE so i tried writing my own static methods to do the job because I read somewhere that Arrays.copyOf only works for one dimensional arrays.

thanks for any help you can offer, Cheers

    public class ex7_imageSmoother {
        public static void main ( String[] args ) throws IOException {
            
    //  build utility object(s)
        Scanner ScUser = new Scanner( System.in );

    //  ph for ascii art
        System.out.println( "\n\nAre your ready to Soften some \"hard\" files?" );

      ////..repeat program by prompt
            String stRepeat1;
            do {
        
        //  get hard file name to be softened
            System.out.print( "\n\nWhat file would you like to soften? " );

            String  StHardName = ScUser.nextLine().trim();
            File    FiHardIn   = new File   ( StHardName );
            Scanner ScHardIn   = new Scanner( FiHardIn );
        
      //--  build 2d "Hard" array
        //  array will be of at least one cell
            int[][] AyHardImg = { { 0 } } ;  
 
            int iRowCount = 0;
        
      ////  for every line in the file; i.e. check that there is a next line
            while (ScHardIn.hasNextLine() ) {
                
            //  create a string that can be read through by scanner for every line of the file
                String StInLine = ScHardIn.nextLine();
            //  build scanner to read through each row
                Scanner ScInLine = new Scanner( StInLine );
                
            //  use static method to copy array; make larger on further iterations
                AyHardImg = smCopyArrayOuter( AyHardImg, iRowCount );
                
                int iColCount = 0;

          ////  for every integer in the row
                while ( ScInLine.hasNextInt() ) {
                    
                //  create temporary array in an attempt to circumvent NPE
                    int[] temp = new int[ AyHardImg[ iRowCount ].length ]; // ...--... this line creates the NPE!!
                
                //  copy into temp array all values from inner array of 2d array
                    for (int i = 0; i < AyHardImg[ iRowCount ].length; i++) {
                        temp[ i ] = AyHardImg[ iRowCount ][ i ];
                    }
                    
                //  copy array and make larger on further iteration
                    temp  = smCopyArrayInner( temp, iColCount );
            
                //  use temp array to copy into 2d inner array; included is commented out previous attempt without temp array
                    AyHardImg[ iRowCount ]  = temp; //= smCopyArray( AyHardImg[ iRowCount ], iColCount );
                    AyHardImg[ iRowCount ][ iColCount ] = ScInLine.nextInt();

                    iColCount++;
                }

                iRowCount++;
                ScInLine.close();
            }
            
        //  test algorithm works as intended by printing hard array to screen
            for ( int i = 0; i < AyHardImg.length; i++ ) {
                for ( int j = 0; j < AyHardImg[i].length; j++ ) {
                    System.out.print ( AyHardImg[ i ][ j ] + " " );
                }
                System.out.println();
            }

            ScHardIn.close();

        //  get user response to repeat program
            System.out.print( "Would you like to soften another file (y/n)? " );
            stRepeat1 = ScUser.nextLine().trim().toLowerCase();
        } while ( stRepeat1.equals( "y" ) );


    }


    /*-----
     * copies inner array, hopefully to solve null
     * pointer exception
     *------------------*/

    public static int[] smCopyArrayInner( int[] AyX, int growth ) {
    
        int[] AyY = new int[ AyX.length  +growth ];

        for ( int i = 0; i < AyX.length; i++ ) {
            AyY[ i ] = AyX[ i ];
        }

        return AyY;
    }


    /*-----
     * copies outer array, hopefully to solve null
     * pointer exception
     *------------------*/

    public static int[][] smCopyArrayOuter( int[][] AyX, int growth ) {
    
        int[][] AyY = new int[ AyX.length  +growth ][];

        for ( int i = 0; i < AyX.length; i++ ) {
            AyY[ i ] = AyX[ i ];
        }

           return AyY;
        }
    }