【问题标题】:Java 8 compilation and execution errorJava 8 编译和执行错误
【发布时间】:2015-01-30 17:11:31
【问题描述】:

为了在 NLP 项目中使用最新的斯坦福软件包,我将 Eclipse 升级到 Java 8,如下所示:http://eclipse.org/downloads/java8/。在将合规性路径更改为 Jdk1.8 和所有其他相应更改后,我运行了该程序。

这是错误:

错误:在 edu.stanford.nlp.trees.tregex.Relation$17 类中找不到主要方法,请将主要方法定义为:public static void main(String[] args) 或 JavaFX 应用程序类必须扩展 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);
    }

}

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

【问题讨论】:

  • 没有public static void main(String[] args) 方法。 Java 提供了正确的错误。
  • @LuiggiMendoza 这让我很困惑。它在第八行。
  • 好吧,看起来您正在edu.stanford.nlp.trees.tregex.Relation 内部执行一个名为 17 的内部类,而不是您的Readability 类。检查您是如何执行 Java 应用程序的。
  • 我选择了可​​读性,然后运行它,我得到了这个错误:错误无法读取可读性主类。
  • 首先检查类是否编译,然后确保您从正确的项目执行正确的类。

标签: java eclipse stanford-nlp


【解决方案1】:

我刚刚在 Eclipse 上运行这个类,注释掉 MaxentTagger 代码行(因为我没有这个包)并使用 System.out.println("Hello World") 它编译并运行得很好。

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

【讨论】:

  • 主类:可读性和项目:项目(我的项目的名称)。并检查以下内容: 1. 在搜索主类时包含系统库。 2. 搜索主类时包括继承的主类。 3. 停在主站。
  • 运行时:可读性 [Java 应用程序] C:\Program Files\Java\jdk1.8.0_31\binjavaw.exe
  • 我一直在 jre 7 上运行它。我删除了所有其他版本,然后安装。现在可以了。
猜你喜欢
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多