修复我的java类中的数组类型和方法错误,真的不知道如何修复错误
我在运行解析器程序时出现以下错误修复我的java类中的数组类型和方法错误,真的不知道如何修复错误,java,arrays,parsing,compiler-errors,runtime-error,Java,Arrays,Parsing,Compiler Errors,Runtime Error,我在运行解析器程序时出现以下错误 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方法中,有这样一个错误,但是我已经在parser类
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方法中,有这样一个错误,但是我已经在parser类中创建了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.io.BufferedReader;
导入java.io.File;
导入java.io.FileNotFoundException;
公共类文档解析器{
私人无效剂量(){
String text=“教授、工程、数据、挖掘、研究”;
StringTokenizer str=新的StringTokenizer(文本);
字符串字[]=新字符串[10];
字符串唯一[]=新字符串[10];
字符串x;
整数计数=-1;
while(str.hasMoreTokens()){
计数++;
x=str.nextToken();
if(f.getName().endsWith(“.txt”)){
in=新的BufferedReader(新的文件读取器(f));
StringBuilder sb=新的StringBuilder();
字符串s=null;
而((s=in.readLine())!=null){
某人追加;
}
字符串[]tokenizedTerms=sb.toString().replaceAll(“[\\W&&[^\\s]]”,“”)。拆分(\\W+”;//以获取单个术语
for(字符串术语:tokenizedTerms){
如果(!allTerms.contains(term)){
所有条款。添加(条款);
}
}
termsDocsArray.add(标记化术语);
}
}
}
public void tfidf计算器(){
双tf;
双idf;
双tfidf;
for(字符串[]docTermsArray:termsDocsArray){
double[]tfidfvectors=新的double[allTerms.size()];
整数计数=0;
for(字符串术语:allTerms){
tf=新的TfIdf().getTf(docTermsArray,terms);
idf=新的TfIdf().idf计算(术语Docsarray,术语);
tfidf=tf*idf;
tfidfvectors[count]=tfidf;
计数++;
}
添加(tfidfDocsVector);
}
}
public void getCosineMatrix(){
对于(int i=0;i
您的主方法被注释掉了,这就是为什么编译器找不到它的原因。
for循环不在方法内部,只在类主体中。这在java中是错误的。
编译器发出的错误消息准确地告诉您要做什么,您必须提供一个特殊的构造函数来处理异常。阅读错误消息,然后检查代码:
错误:在类TfIdfMain中找不到Main方法,请将Main方法定义为:
公共静态void main(字符串[]参数)
有什么问题吗?未找到主要方法。在代码中,它被注释掉了
在您的TfIdfMain
-类中:
至少for循环必须在方法/构造函数中。
做点像
public class TfIdfMain
public TfIdfMain(){
for(String file : files) {
DocumentParser dp = new DocumentParser();
dp.parseFiles(file);
dp.getCosineMatrix();
}
}
}
非常感谢你!我已经在这个代码上工作了好几个小时了!因为我再过一个小时就不能发帖了,我不知道你是否会在晚些时候出现。我正在努力让这个代码正常工作。我可以给你发电子邮件吗?我的电子邮件是gmail上的firstjavapython,这是一个临时帐户,所以你不用担心隐私问题。请帮帮我!我真的需要你的帮助!谢谢,我给你发了电子邮件。您现在可以删除您的电子邮件评论。