[英]Jama Matrix printwriter error
我在我的項目中使用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
我用intellj的想法簡化了這段代碼。 誰能告訴我為什么會出現此錯誤?
我確實檢查了Matrix.java的Jama api 。 看來您正在嘗試使用以下代碼段中帶有三個參數的print方法。 請正確重寫。
如下修復
A.print(write1,9,6);// error in this line
我解決了這個問題。 我認為這對於那些剛接觸Jama Matrix並遇到類似問題的人很有幫助。 這是我的解決方案:
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 Matrix的文檔很少,我認為這對讀者確實很有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.