svd错误java java空指针异常

时间:2016-01-26 19:36:55

标签: java jama

我正在编写一个代码,它使用线程来使用Jama和svd()方法从矩阵A访问矩阵U,S和V,但我遇到了像Java Null指针异常这样的困难。我的代码是这样的:

 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;

现在,当我尝试创建3个这样的SVD对象时:

[out:json];
is_in(34.0500, -118.2500);
out;

{
  "type": "area",
  "id": 3600148838,
  "tags": {   
           "admin_level": "2",
           "border_type": "national",
           "boundary": "administrative",
           "name": "United States of America",
           "type": "boundary",
           "wikidata": "Q30",
           "wikipedia": "en:United States"
          }
},

{
  "type": "area",
  "id": 3600165475,
  "tags": {
           "ISO3166-2": "US-CA",
           "admin_level": "4",
           "boundary": "administrative",
           "name": "California",
           "type": "boundary"
          }
},
{
 "type": "area",
 "id": 3600207359,
 "tags": {
          "admin_level": "8",
          "boundary": "administrative",
          "name": "Los Angeles",
          "place": "city",
          "short_name": "LA",
          "type": "boundary"
         }
}

最后一行是获取错误的行。什么可能导致问题?这是我错过的东西?

PS:对不起格式化我不知道为什么会这样!

1 个答案:

答案 0 :(得分:0)

结果来自Matrix类型,虽然你的a1指向某个东西,a1.result可能为null,尝试在你执行最后一行之前调用run方法,如:

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();
a1.run();
Matrix U=a1.result;

检查a1.run()行,以便从a1初始化结果字段。