0

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));
高鵬翔
  • 1,997
  • 2
  • 8
  • 21
  • 1
    See [here](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) for more information on NullPointerExceptions and their cause. In your case, I would guess (with the info you provided) that `jTable1.getValueAt()` is causing the exception. So the cell you retrieve might be `null` and you try to parse it. Without any more information, there is no hint on why exactly the value might be null. – maloomeister Jul 08 '20 at 08:15
  • I have tried checking the results through the system outprint and the data appears, but it cannot be entered into the array – Peter Gigih Jul 08 '20 at 08:21
  • 1
    Ah now I see the issue. You initialized your `double[] normalisasiT1` with `null`. Before accessing an array, you need to initialize it in java, which means, you provide the information on how big the array is going to be. For more information on arrays [here](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html). So to fix your problem, initialize your array like `double[] normalisasiT1 = new double[sizeOfYourArray]`. – maloomeister Jul 08 '20 at 08:26
  • Oh its work, thanks sir – Peter Gigih Jul 08 '20 at 08:31

1 Answers1

0

you should initialize the array

normalisasiT1 = new double [sizeOfIt];

the array is null so it throws NPE.