我在我的项目中使用JAMA矩阵。我需要在文本文件中写下一个Jama矩阵。为此,我写下了这段代码。
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);
}
}
}但它会抛出错误:
/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我把这段代码记下来了。有人能告诉我为什么我会犯这个错误吗?
发布于 2018-06-05 18:39:18
我确实检查了Jama api接口的Matrix.java。在下面的代码段中,您似乎尝试使用带有三个参数的print方法。请把它重新写好.
按下面的方式修复
A.print(write1,9,6);// error in this line 发布于 2018-06-06 08:34:11
我解决了这个问题。我认为这对那些刚接触过Jama矩阵并面临这样一个问题的人是有帮助的。这是我的解决方案:
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);
}
}
}这解决了我的问题。由于JAMA矩阵的文档非常少,我认为这对读者确实有帮助。
https://stackoverflow.com/questions/50706716
复制相似问题