How to Insert Data To Array

Tags: , , ,



I want to save a “AromaNorm” into NormalisasiT1 array, but i had a error :

AWT-EventQueue-0 java.lang.NullPointerException

Can you help me? Here the Code

double[] normalisasiT1 = null;
    
    double nilaipembagi = Math.sqrt(Aroma);
    
     for (int i =0; i< jTable1.getRowCount(); i++){
           double aroma1 = Double.parseDouble((String)jTable1.getValueAt(i, 2));
           double AromaNorm = aroma1/nilaipembagi;
           normalisasiT1[i] = AromaNorm;
    }
     System.out.println(Arrays.toString(normalisasiT1));

Answer

you should initialize the array

normalisasiT1 = new double [sizeOfIt];

the array is null so it throws NPE.



Source: stackoverflow