java - How to store the ArrayList in matrix format and ArrayList Should be String data? -


in code got error arrayoutofboundexception , nullpointerexception in ml.getv() method

this matrix class

public class matrix {     private double [][] v = null; // public members     public static int rowsofvmatrix = 9219;     public static int colsofvmatrix = 5;     public static int row_increase = 20;      public double[][] getv() {         return v;     }     public void setv(double[][] v) {         v = v;     }     public static int getrowsofvmatrix() {         return rowsofvmatrix;     }     public static void setrowsofvmatrix(int rowsofvmatrix) {         rowsofvmatrix = rowsofvmatrix;     }     public static int getcolsofvmatrix() {         return colsofvmatrix;     }     public static void setcolsofvmatrix(int colsofvmatrix) {         colsofvmatrix = colsofvmatrix;     }     public static int getrow_increase() {         return row_increase;     }     public static void setrow_increase(int row_increase) {         row_increase = row_increase;     }     public matrix(){         v = new double[matrix.rowsofvmatrix][matrix.colsofvmatrix];     }     public matrix(int rowssize, int colsize){         matrix.rowsofvmatrix = rowssize;         matrix.colsofvmatrix = colsize;         v = new double[matrix.rowsofvmatrix][matrix.colsofvmatrix];     }     public matrix(matrix m){         v = new double[matrix.rowsofvmatrix][matrix.colsofvmatrix];         (int = 0; < matrix.rowsofvmatrix; i++) {             (int j = 0; j < matrix.colsofvmatrix; j++) {                 this.v[i][j] = m.v[i][j];             }         }            } 

i tried code store arraylist in matrix using following code

public static list<matrix> readfromfilegetmatrixlist(string filename)                 throws ioexception {             list<matrix> ml = new arraylist<matrix>();             matrix m = null;             filereader fr = new filereader(filename);             bufferedreader br = new bufferedreader(fr);             string linecontent;             int matrixnum = 0;             while ((linecontent = br.readline()) != null) {                 if (linecontent.contains("#")) {                     matrixnum++;                 }             }         matrixnum--;// last 1 may incomplete,so remove list             br.close();             fr.close();             fr = new filereader(filename);             br = new bufferedreader(fr);             int matrixrow_index = 0;             int matrixcount = 0;             while ((linecontent = br.readline()) != null) {                 if (linecontent.contains("#")) {                     if (matrixcount > 0) {                         ml.add(m);                         matrixrow_index = 0;                     }                     if (matrixcount == matrixnum)                         break;                     m = new matrix();                     continue;                 }                 if (linecontent.equals("")) {                     matrixcount++;                     continue;                 }                 string[] str = linecontent.split("\t");                 (int j = 0; j < str.length; j++) {                     m.getv()[matrixrow_index][j] = double.parsedouble(str[j]); //null pointer exception      }                 matrixrow_index++;             }             return ml;         } 

this text file sample

0 qid:1 1:1.000000 2:0.693147 3:0.166667 #docid = 285257 0 qid:1 1:1.000000 2:0.693147 3:0.166667 #docid = 285285 0 qid:1 1:1.000000 2:0.693147 3:0.166667 #docid = 285289 0 qid:1 1:1.000000 2:0.693147 3:0.166667 #docid = 285245

in above code getting arrayboundofindexerror


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -