针对各种行长度将字符串矩阵转换为双矩阵

时间:2017-09-07 12:48:09

标签: java

我正在尝试将字符串矩阵转换为双矩阵,但继续收到此错误:

Exception in thread "main" java.lang.NullPointerException
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
    at java.lang.Double.parseDouble(Unknown Source)
    at wim_data_reader.WIMdataReader.main(WIMdataReader.java:135)

矩阵中的每一行不一定与前一行的大小相同。这是我的代码:

 //double matrix to store all the converted string elements
 double[][] data = new double[WIMdataMatrix.length][];

 //double for loop used to convert string elements to double elements and store them in matrix
 for (int i = 0; i < WIMdataMatrix.length; i++) {

     //
     data[i] = new double[WIMdataMatrix[i].length];

     for (int j = 0; j < WIMdataMatrix[i].length; j++) {

         data[i][j] = Double.parseDouble(WIMdataMatrix[i][j]);

     }
 }   

请帮忙!

0 个答案:

没有答案