Matrix multiplication in BlueJ (Java)

129 Views Asked by At

can anyone find me the mistake in the following code?

This is the multiplication of matrices that contain fractions. It shows me a NullPointerException and underscores the line with z[i][j]. The scitaj and vynasob methods are already tested and the error should not be there. I am attaching a picture. If you need to see a larger part of the code for understanding, tell me.

Thank you very much :)

matica - matrix zlomok - fraction nasobenie, vynasob - multiplication PocetRiadkov - number of rows PocetStlpcov - number of columns scitaj - +

public Matica nasobenie() {
    Matica xs = new Matica(new Zlomok[][]
    {
        {new Zlomok(1, 1), new Zlomok(2, 1), new Zlomok(3, 1)},
        {new Zlomok(4, 1), new Zlomok(5, 1), new Zlomok(6, 1)}
    });
        
    Matica ys = new Matica(new Zlomok[][]
        {
            {new Zlomok(7, 1), new Zlomok(8, 1)},
            {new Zlomok(9, 1), new Zlomok(10, 1)},
            {new Zlomok(11, 1), new Zlomok(12, 1)}
        });
    
    Zlomok [][] z = new Zlomok[xs.getPocetRiadkov()][ys.getPocetStlpcov()];
    System.out.println(z);
    for (int i = 0; i < z.length; i++) {
        for (int j = 0; j < z[0].length; j++) {
            for (int k = 0; k < xs.getPocetStlpcov(); k++) {
                z[i][j] = z[i][j].scitaj(xs.getPrvok(i, k).vynasob(ys.getPrvok(k, j)));
            }
            System.out.println();
        }
    }
    Matica vysledok = new Matica(z);
    return vysledok;        
}
0

There are 0 best solutions below