【发布时间】:2016-07-21 06:35:43
【问题描述】:
运行解析器程序时出现以下错误,
Error: Main method not found in class TfIdfMain, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
同样在我的main方法中,有这样的错误,但是我已经在解析器类中创建了parserfile错误,
Multiple markers at this line
- Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit
constructor
- Default constructor cannot handle exception type FileNotFoundException thrown by implicit super constructor. Must define an
explicit constructor
同样在我的解析器类中,数组列表行周围有一个错误,它说数组无法解析,我应该如何解决这个问题?创建一个新变量。
这是我的两个主要类涉及的错误:
import java.io.FileNotFoundException;
import java.io.IOException;
public class TfIdfMain {
}
// public static void main(String args[]) throws FileNotFoundException, IOException {
// DocumentParser dp = new DocumentParser();
// dp.parseFiles("C:\\Users\\Sarah\\Documents");
// dp.getCosineMatrix();
// }
}
}
我的文档解析器类:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
public class DocumentParser {
private void doSomething(){
String text = "Professor, engineering, data, mining, research";
StringTokenizer str = new StringTokenizer(text);
String word[] = new String[10];
String unique[] = new String[10];
String x;
int count = -1;
while (str.hasMoreTokens()) {
count++;
x = str.nextToken();
if (f.getName().endsWith(".txt")) {
in = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String s = null;
while ((s = in.readLine()) != null) {
sb.append(s);
}
String[] tokenizedTerms = sb.toString().replaceAll("[\\W&&[^\\s]]", "").split("\\W+"); //to get individual terms
for (String term : tokenizedTerms) {
if (!allTerms.contains(term)) {
allTerms.add(term);
}
}
termsDocsArray.add(tokenizedTerms);
}
}
}
public void tfIdfCalculator() {
double tf;
double idf;
double tfidf;
for (String[] docTermsArray : termsDocsArray) {
double[] tfidfvectors = new double[allTerms.size()];
int count = 0;
for (String terms : allTerms) {
tf = new TfIdf().getTf(docTermsArray, terms);
idf = new TfIdf().idfCalculation(termsDocsArray, terms);
tfidf = tf * idf;
tfidfvectors[count] = tfidf;
count++;
}
tfidfDocsVector.add(tfidfvectors);
}
}
public void getCosineMatrix() {
for (int i = 0; i < tfidfDocsVector.size(); i++) {
for (int j = 0; j < tfidfDocsVector.size(); j++) {
System.out.println("between " + i + " and " + j + " = "
+ new CosineSimilarity().getCosine
(
tfidfDocsVector.get(i),
tfidfDocsVector.get(j)
)
);
}
}
}
}
【问题讨论】:
标签: java arrays parsing compiler-errors runtime-error