Java 数组硬件中的取消引用错误

Dereferncing Error In Java Array HW

我在以下代码中遇到有关取消引用的错误(我已经注释掉它被捕获的地方)

main 方法工作正常,但 Mply 方法让我很头疼。希望这有点清楚。

    //multiply matrixes
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.StringTokenizer;
public class Assignment1 {
    public static void main(String[] args){
      int a=5;
      int b=2;
      int x[][] = new int[a][b];
          for(int i=0;i<a;i++)
            for(int j=0;j<b;j++)
                x[i][j]=0;
        System.out.println(x[1][1]);
        /*
     for(int j= 0; j<                                    
      for (int i = 0; i < array.length; i++)
        array[i] = s.nextInt();
        */
        // read from file

        FileInputStream fstream=null;
        try{
           fstream = new FileInputStream("C:\javastuff\principles\input.txt");

        }
        catch (Exception e){
            System.out.println(e.getMessage());
        }
        try (BufferedReader br = new BufferedReader(new InputStreamReader(fstream))) {
                 String line;
           while ((line = br.readLine()) != null) {
                   System.out.println(line);

                    /* StringTokenizer tokenizer = new StringTokenizer(line, " ");
                       while (tokenizer.hasMoreElements()) {
                           // parse each integer in file
                           int i = Integer.parseInt(tokenizer.nextToken());
                     System.out.println("Number " + i);
                       }
                 */




           }
           br.close();
         }
        catch(Exception e){

        }

        // write to file

      BufferedWriter outputWriter = null;
       try{
         outputWriter = new BufferedWriter(new FileWriter("C:\javastuff\principles\output.txt"));

        for (int i = 0; i < a; i++) {

            outputWriter.write(Integer.toString(x[i][0]));
            outputWriter.newLine();
        }
            outputWriter.flush();  
            outputWriter.close();

             }
         catch (Exception e){

         }

    }
    public static void Mply(int x[][], int a, int b){ //multiplies arraries and checks if they are same values
       int aRows = a.length;
        int aColumns = a[0].length;//starts dereferecning herer
        int bRows = b.length;
        int bColumns = b[0].length;

      for (int i=0; i<a; ++i)
        for (int j=0; j<b; ++j)
        for (int k=0; k<a[0][0].length(); ++k)
        x[i][k] += a[i][k] * b[k][j];
    }
}

基于 header 方法 Mply

public static void Mply(int x[][], int a, int b)

x的类型是int[][]a的类型是intb的类型是int .具体来说,请注意 ab 而不是 数组。

因此尝试使用 a[0] 将它们作为数组访问是非法的。

如果您希望 ab 成为二维数组,则必须更新您的方法 header 以实现这一点。

public static void Mply(int[][] x, int[][] a, int[][] b)