小编eld*_*222的帖子

正在抛出NullPointerException,但我无法弄清楚如何修复它.

我有以下代码.它是Matrix类的构造函数.主线程只调用构造函数,然后打印矩阵(我为它创建了一个方法).

public class Matrix{ 
    float [][] mainMatrix; 
    int rows; 
    int columns; 
    public Matrix(){
        System.out.printf("\nInput the number of rows \n") ;
    String rowR = new Scanner(System.in).next().replace(" ", "").replace("\n", "").toString();
    rows = Integer.parseInt(rowR);
    System.out.printf("\n Input the number of columns \n");
    String columnR = new Scanner(System.in).next().replace(" ", "").replace("\n", "").toString();
    columns = Integer.parseInt(columnR);
    System.out.printf("Input the rows, seperated by a \" \". Close the row with a \"]\"");
    System.out.println("Warning!!! Inproper input will cause the program to crash!"); 
    for(int r = 0; r < rows; r++){ …
Run Code Online (Sandbox Code Playgroud)

java matrix nullpointerexception

0
推荐指数
1
解决办法
103
查看次数

标签 统计

java ×1

matrix ×1

nullpointerexception ×1