Hello Members,

I am trying to multiply two matrices using multithreading. I get a NullPointerException on the line that is commented in Bold.

Following is the entire code. Any input is much appreciated.

import java.lang.*;
import java.io.*;




public class Matrix_Mult extends Thread
{
    static int a[][]; static int b[][]; static int c[][];
    static int n = 3;
    int row;
    
    Matrix_Mult(int p)
    {
        row =p;
        
        this.start();
    }
    
    public void run()
    {
        int i, j;
        
        for (i=0; i<n; i++)
            {
                
                for (j=0; j<n; j++)
                    {
                        c [row][i] += a[row][j] * b[j][i]; [B]//[B][B]NullPointerException on this line[/B][/B][/B]
                        
                        
                    }
             }
      }
 

  
public static void main(String args[])
{
    int a [][] =  { {1,2,3}, {4,5,6}, {7,8,9}};
    int b [][] = { {1,2,3}, {4,5,6}, {7,8,9}};
    int c [][] = { {0,0,0}, {0,0,0}, {0,0,0}};
    
   
    
    Matrix_Mult  y [] = new Matrix_Mult[n];
    
    for (k=0; k<n; k++)
        {
            y[k] = new Matrix_Mult(k);
        }
        
    try {
    for (i=0; i<n; i++)
        {
            y[i].join();
        }
    }
    catch (Exception e)
    {}

  }
}

Edited 6 Years Ago by sciprog1: n/a

Hello Ezzaral,

Thank you!! Should have noticed it. It works now.

Regards,
Sciprog1

This question has already been answered. Start a new discussion instead.