java怎么引用一个类的get()函数,返回的是数组;
package com.example.wivedraw;
public class CreatData {
private float amp;
private float T;
private float curX;
private double[] arr;
public boolean init(){
amp = 40f;
T = 125f;
arr = new double[125];
curX = 0f;
return true;
}
public double[] getDatas(){
double deg = 0.0, rad = 0.0;
for(int i = 0 ; i < arr.length ;i++){
deg = (curX % T)*(2*180) / T; //[0,2*pi]
rad = Math.toRadians(deg) ;
arr[i] = amp * Math.sin(rad);
curX++;
}
curX = 0;
return arr;
}
}
显示的错误是Attempt to get length of null array
我需要在其他类调用上面的getData()函数
调用代码是
CreatData creatData = new CreatData();
double[] data = creatData.getDatas();