Java8 编译执行错误

Java 8 compilation and execution error

为了将最新的 Stanford 软件包用于 NLP 项目,我将 Eclipse 升级到 Java 8,如:http://eclipse.org/downloads/java8/。在将合规性路径更改为 Jdk1.8 以及所有其他相应更改后,我 运行 程序。

这是错误:

Error: Main method not found in class edu.stanford.nlp.trees.tregex.Relation, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

程序如下:

import java.io.*;
import java.util.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Readability 
{
    static String line1;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public static void main(String args[])throws IOException
    {
        Readability rd=new Readability();
        rd.tag(rd.count());
    }      
    public String count()throws IOException
    {
        String line, line1;
        System.out.println("Enter the name of the file: ");
        String file=br.readLine();
        StringTokenizer st = null;
        StringBuilder sb=new StringBuilder();
        try(FileInputStream input = new FileInputStream("E:\"+file))
            {
            int data = input.read();
            while(data != -1)
                {
                sb.append((char)data);
                data = input.read();
                }
            }
        catch(FileNotFoundException e)
        {
            System.err.println("File Not Found Exception : " + e.getMessage());
        }
        line=sb.toString();
        double sentencecount=0.0000, syllablecount=0.0000;
        st = new StringTokenizer(line," ,(){}[]/.;:'&?!\r\t\n\f");
        StringTokenizer st1 = new StringTokenizer(line,"\r");
        double wordcount=st.countTokens();
        System.out.println(wordcount);
        line1=line;//copy for Tagger
        line+=" T";
        //System.out.println(line);
        char[] array = line.toCharArray();
        for (int i=0;i<array.length-1;i++)
        {
            int turn=i+2;
            if(array[i]=='?')
                sentencecount++; 
            if((array[i]=='.')&&(((int)array[turn]>64&&(int)array[turn]<91)))
                sentencecount++;
            if((array[i]=='!')&&(((int)array[turn]>64&&(int)array[turn]<91)))
                sentencecount++;
            if((array[i]=='\'')&&(((int)array[turn]>64&&(int)array[turn]<91)))
                sentencecount++;
            if((array[i]=='"')&&(((int)array[turn]>64&&(int)array[turn]<91)))
                sentencecount++;
        }
        System.out.println(sentencecount+(st1.countTokens()-1));//To include the last sentence before the 'Enter' is pressed as the ' ' follows a '.'
        //System.out.println(st1.countTokens());
        char[] array1=new char[st.countTokens()];
        while (st.hasMoreTokens()) 
        {
            array1=st.nextToken().toCharArray();
            if(array1.length>2)
            {
            for(int i=0;i<array1.length-1;i++)
            {
                char a=Character.toLowerCase(array1[i]);
                char b=Character.toLowerCase(array1[i+1]);
                //System.out.println(a+" "+b);
                if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
                {
                    if(b!='a'&&b!='e'&&b!='i'&&b!='o'&&b!='u')
                    {
                        //System.out.println("Swab");
                        syllablecount++;
                    }
                }
            }

            char c=Character.toLowerCase(array1[array1.length-1]);
            char d=Character.toLowerCase(array1[array1.length-2]);
            //System.out.println(c+" "+d);
            if((c=='a'||c=='i'||c=='o'||c=='u')&&(d!='a'||d!='e'||d!='i'||d!='o'||d!='u'))
            {
                //System.out.println("Ha!");
                syllablecount++;
            }
            else if((c=='e')&&(d=='e'))
            {
                //System.out.println("Hola");
                syllablecount++;
            }
            }
            else
            {
                //System.out.println("Woosh");
                syllablecount++;
            }
        }
        StringTokenizer st2 = new StringTokenizer(line," ,(){}[]/.;:'&?!\r\t\n\f");//As 'The' doesn't come under the syllable count radar
        while (st2.hasMoreTokens()) 
        {
            String a=st2.nextToken();
            //System.out.println(a);
            if(a.equalsIgnoreCase("the"))
            {
                syllablecount++;
            }
        }
        System.out.println(syllablecount);
        double readability=(206.835-(1.015*(wordcount/sentencecount))-(84.6*(syllablecount/wordcount)));
        System.out.println("\nReadability Measure:\n\n90-100: Easily Understood by an average 11-year old.\n60-70: Easily understood by a 13-15 year old.\n0-30: Best understood by university graduates.");
        if(readability>0&&readability<100)
            System.out.println("The readability score, according to Flesch readability measure is: "+readability);
        else
        System.out.println("\nThe Readability score, according to Flesch readability measure is: "+100);
        return line1;
    }
    public void tag(String st)
    {
        //System.out.println(st);
        MaxentTagger tagger = new MaxentTagger("Tagger/left3words-distsim-wsj-0-18.tagger");
        String tagged = tagger.tagString(st);    
        System.out.println(tagged);
    }

}

至于代码:它寻求获得单词,句子和音节的数量。为了使用 Stanford POS 标注器,我需要 Java 8,因为错误是不受支持的主要次要版本。因此变化。

我只是 运行 这个 class 在 Eclipse 上注释掉 MaxentTagger 代码行(因为我没有这个包)并使用 System.out.println("Hello World" ) 并编译并且 运行 就好了。

程序看起来不错。右键单击 Readability 程序并点击 运行 as -> Java Application。我的猜测是您正在从 Eclipse 工具栏中点击 运行 并且它与以前的一些设置挂钩。如果我所说的没有解决它,那么点击 运行 as -> 运行 配置并检查项目和 Main Class 是 运行 是否正确。除此之外,您的代码没问题。