Jama Matrix printwriter error

114 views Asked by At

I am using JAMA matrix in my project. I need to write down a Jama matrix in text file. For that I write down this code.

package Xdata;
import Jama.Matrix;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;


public class File_r {
public static void main(String args[]) {


 Matrix A = new Matrix(10, 10);
    try {
        PrintWriter write1 = new PrintWriter(new File("/home/robotics//IdeaProjects/Data_arrange/src/Xdata/mu_X.txt"));
        A.print(PrintWriter write1,9,6);// error in this line
     }
    catch(FileNotFoundException ex) {
        System.out.println(ex);

        }
    }
}

But it throws errors:

/home/robotics/IdeaProjects/Data_arrange/src/Xdata/File_r.java
Error:(13, 32) java: ')' expected
Error:(13, 33) java: not a statement
Error:(13, 39) java: ';' expected

I wtite down this code in intellj idea. Can any one tell me why I get this error?

2

There are 2 answers

2
Yohannes Gebremariam On BEST ANSWER

I did check the Jama api for Matrix.java. it looks you are trying to use the print method with three parameter in the below snippet . please re-write it correctly.

fix it as below

 A.print(write1,9,6);// error in this line 
1
Saswati On

I solved this problem. I think it is helpful for those who are new to Jama Matrix and face a problem like that. Here is my Solution:

package Xdata;
import Jama.Matrix;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

 public class File_r {
public static void main(String args[]) {
    Matrix A = new Matrix(10, 10);
    PrintWriter writer=null;
    try {
         writer = new PrintWriter("/home/robotics//IdeaProjects/Data_arrange/src/Xdata/mu_X.txt");// So basically I change this line
        A.print(writer,2,2);
        writer.close();// Add this line

    }
    catch(FileNotFoundException ex) {
        System.out.println(ex);

    }
  }
}

This solve my problem. As there is very less documentation of JAMA Matrix I think this is really help ful for reader.