Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java //如果 // //区域 //是一个 //0或 //“无标记” System.out.println(“计算机缺失”+计算机选择X +“+计算机选择”; boardGraphical[computerChoiceX][computerChoiceY]=“x”;//做记号 //区域 //作为一个 //错过 对于(int row=0;row_Java_Arrays_Class_Object_Nullpointerexception - Fatal编程技术网

Java //如果 // //区域 //是一个 //0或 //“无标记” System.out.println(“计算机缺失”+计算机选择X +“+计算机选择”; boardGraphical[computerChoiceX][computerChoiceY]=“x”;//做记号 //区域 //作为一个 //错过 对于(int row=0;row

Java //如果 // //区域 //是一个 //0或 //“无标记” System.out.println(“计算机缺失”+计算机选择X +“+计算机选择”; boardGraphical[computerChoiceX][computerChoiceY]=“x”;//做记号 //区域 //作为一个 //错过 对于(int row=0;row,java,arrays,class,object,nullpointerexception,Java,Arrays,Class,Object,Nullpointerexception,您使用myArray,但从未初始化它 public class Caculations { int xValue; int yValue; int[][] myArray; // array declared but never initialized // .... void findShip() { while (notSunk == true) { // 1 while (xAxisChangeP == t

您使用myArray,但从未初始化它

public class Caculations {
   int xValue;
   int yValue;
   int[][] myArray;  // array declared but never initialized

   // ....

   void findShip() {
      while (notSunk == true) {
         // 1
         while (xAxisChangeP == true) {
            if (myArray[xValue + 1][yValue] == 1)  // then you use it here
解决方案:在使用前初始化变量


更重要的是,您需要学习如何调试NPE(NullPointerException)的一般概念您应该仔细阅读异常的stacktrace,找到出错的代码行,即引发异常的代码行,然后仔细检查该行,找出哪个变量为null,然后回溯到代码中以了解原因。相信我,您会一次又一次地遇到这些问题。

您使用myArray,但从未初始化它

public class Caculations {
   int xValue;
   int yValue;
   int[][] myArray;  // array declared but never initialized

   // ....

   void findShip() {
      while (notSunk == true) {
         // 1
         while (xAxisChangeP == true) {
            if (myArray[xValue + 1][yValue] == 1)  // then you use it here
解决方案:在使用前初始化变量


更重要的是,您需要学习如何调试NPE(NullPointerException)的一般概念您应该仔细阅读异常的stacktrace,找到出错的代码行,即引发异常的代码行,然后仔细检查该行,找出哪个变量为null,然后回溯到代码中以了解原因。相信我,您会一次又一次地遇到这些问题。

您初始化myarray了吗?最好的方法是调试代码以查看哪条语句引发异常。在eclipse中,您可以添加NullPointerExeption作为断点并进行调试。

您初始化myarray了吗?最好的方法是调试代码以查看哪条语句引发异常。在eclipse中,您可以添加NullPointerExeption作为断点并进行调试。

计算的构造函数中,您从未初始化过
myArray

Caculations(int x, int y, int[][] myArray) {
    xValue = x;
    yValue = y;
    xAxisChangeP = true;
    yAxisChangeP = true;
    xAxisChangeN = true;
    yAxisChangeN = true;
    notSunk = true;
    this.myArray = myArray; //Add this line
}
这是对你问题的直接回答,但总的来说,你应该做一些关于这个问题背后含义的研究