简体   繁体   中英

Getting bidimensionnal preset array out of an class

I would like to use a bidimensionnal array - where i store values as a preset - out of my class. Here is my class :

public class preset 
{
  double arrayPreset[][] = {
                            {
                              // First dimension of array (x values)
                              3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 
                              11.0, 11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 
                              17.5, 18.0,18.5, 19.0, 19.5, 20.0
                            }, 
                            {
                              // Second dimension of array (y values)
                              34, 88, 155, 237, 333, 448, 582,738, 919, 1123, 1351,1604, 1845, 2043, 2200, 
                              2321, 2409, 2467, 2495, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 2500, 
                              2500, 2500, 2500, 2500, 2500, 2500
                            } 
                            };

 public double[][] getArray()
 {
   return this.arrayPreset;
 }
  public preset()
 {
 }
}

And here is my call :

preset defaultPreset = null;

// ERROR
double presetCurve[][] = defaultPreset.getArray();

System.out.println("Get preset");

for(double m = 0.5; m < presetCurve.length; m += 0.5)
{
 System.out.println("m = " +m);
}

My aim is to display if the different values are stocked correctly so that i can parse the array easily. Final goal is to use arrayPreset[x][y] for the point value at x, value at y in a plot.

What am i doing wrong ?

The error message i've got is :

java.lang.NullPointerException
    at IOControl.ReadCSV.run(ReadCSV.java:366) // which is line tagged with a "ERROR" as comment
    at en.window.Main.main(Main.java:46)

Thanks for the time :)

defaultPreset.getArray();

Here defaultPreset is null, which actually become null.getArray() cause this NullPointerException .

You need to create preset Object -

preset defaultPreset = new preset();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM