java - 对象类方法的空点异常
问题描述
我有一个任务是根据另一个名为RBGColor的类创建一个类,我没有源代码,但我被告知代表像素的颜色,如 (0,255,0)。
我已经编写了这个类,但是我的两个方法有一个空点异常。
- 获取宽度
- 到灰度数组
有趣的是 getHight 方法不会抛出该错误。
public class RGBImage{
private RGBColor[][] _image;
final RGBColor DEFAULT_COLOR_VALUE = new RGBColor(0,0,0);
public RGBImage(int rows, int cols) {
RGBColor[][] _image = new RGBColor[rows][cols];
}
public int getHeight(){
int output = _image[0].length;
return output;
}
public int getWidth(){
int output = _image.length;
return output;
}
public double[][] toGrayscaleArray(){
double output[][] = new double[_image.length][_image[0].length];
for (int i = 0; i < _image.length; i++){
for (int j = 0; j < _image[0].length; j++){
output[i][j] = _image[i][j].convertToGrayscale();// this is a method from the RGBColor class
}
}
return output;
}
}
解决方案
推荐阅读
- azure - 在您自己的订阅之外调用 az 函数
- hotjar - 为什么 hotjar 从不截取初始屏幕截图?
- python - 使用除 JS 之外的任何脚本语言自动删除 Firefox 中设置的 Cookie
- ruby-on-rails - 在 Ruby on Rails 控制器中更改记录的值
- reactjs - 将 ReactJS 应用程序部署为 .war
- lua - 我怎样才能使这个lua文件可读
- c++ - 在 RectangleShape 的中心对齐文本
- inext - 如何创建 3 个列表?
- mysql - MySQL视图不超过一种类型
- swift - 如何在 Swift 中划分 UnitMass?