I am writing a little code which is using threads to access the matrixes U, S and V from a matrix A using Jama and svd() method but I'm facing difficulties like Java Null pointer exception. My code is this:
public class SVD implements Runnable
{
private Thread t;
public Matrix A;
public int option;
public Matrix result;
public SVD(Matrix A, int optiune)
{
this.A = A;
this.option = optiune;
}
@Override
public void run()
{
if (option == 1)
result = A.svd().getU();
if(option ==2)
result=A.svd().getS();
if(option ==3)
result=A.svd().getV();
}
public void start()
{
if (t == null)
{
t = new Thread(this);
t.start();
}
}
}
Now when I try to create 3 SVD objects like this:
Matrix A = Matrix.random(20, 20);
SVD a1 = new SVD(A, 1);
SVD a2 = new SVD(A, 2);
SVD a3 = new SVD(A, 3);
a1.start();
a2.start();
a3.start();
Matrix U=a1.result;
The last line is the line which gets the error. What could cause the problem? It is something that I missed?
PS: Sorry for the formatting I don't know why it does that!