简体   繁体   English

Java 8编译和执行错误

[英]Java 8 compilation and execution error

To use the latest Stanford packages for a NLP project I upgraded Eclipse to Java 8, as in: http://eclipse.org/downloads/java8/ . 为了对NLP项目使用最新的Stanford软件包,我将Eclipse升级到Java 8,如: http : //eclipse.org/downloads/java8/ After changing the compliance path to Jdk1.8 and every other corresponding change I ran the program. 将合规性路径更改为Jdk1.8并进行其他相应更改后,我运行了该程序。

This is the error: 这是错误:

Error: Main method not found in class edu.stanford.nlp.trees.tregex.Relation$17, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application 错误:在edu.stanford.nlp.trees.tregex.Relation $ 17类中找不到主要方法,请将该主要方法定义为: public static void main(String[] args)或JavaFX应用程序类必须扩展javafx.application.Application

And here's the program: 这是程序:

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);
    }

}

As for the code: It seeks to get the number of words, sentences and syllables. 至于代码:它试图获得单词,句子和音节的数量。 For using the Stanford POS tagger I needed Java 8 because of the error unsupported major minor version. 对于使用Stanford POS标记器,我需要Java 8,因为该错误不受支持的主要次要版本。 Thus the changes. 因此变化。

I just ran this class on Eclipse commenting out the MaxentTagger lines of code (as I don't have this package) and used System.out.println("Hello World") and it compiled and ran just fine. 我只是在Eclipse上运行该类,注释掉了MaxentTagger代码行(因为我没有此程序包),并使用了System.out.println(“ H​​ello World”),它编译并运行得很好。

The program looks ok. 该程序看起来还可以。 Right click on the Readability program and hit Run as -> Java Application. 右键单击Readability程序,然后单击Run as-> Java Application。 My guess is you are hitting Run from the Eclipse toolbar and that is hooked on to some previous setup. 我的猜测是您从Eclipse工具栏上单击Run,并且已连接到先前的某些设置。 If what I stated didn't fix it, then hit Run as -> Run Configurations and check to see if the project and the Main Class being run are correct. 如果我所说的内容不能解决问题,请单击“运行方式”->“运行配置”,然后检查要运行的项目和Main Class是否正确。 Outside of this, your code is fine. 除此之外,您的代码还可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM