简体   繁体   English

错误:找不到或加载主类

[英]Error: Could not find or load main class

Firstly thank you for your helps. 首先,谢谢您的帮助。 I viewed and tried all of titles like mine but none of them help me to solve my problem. 我查看并尝试了像我这样的所有标题,但没有一个可以帮助我解决问题。 I tried this command in order to compile in current folder that includes ExampleProgram.java: 我尝试使用此命令来在包含ExampleProgram.java的当前文件夹中进行编译:

java -Xms16m -Xmx64m -cp ".:boilerpipe-1.2.0.jar:lib/nekohtml-1.9.13.jar:lib/xerces-2.9.1.jar:lib/langdetect.jar:lib/jsonic-1.2.8.jar" ExampleProgram.java

Then it gives this error: 然后它给出了这个错误:

Error: Could not find or load main class ExampleProgram.java 错误:找不到或加载主类ExampleProgram.java

This is ExampleProgram.java: 这是ExampleProgram.java:

import java.io.InputStream;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;

import org.xml.sax.InputSource;

import de.l3s.boilerpipe.document.TextDocument;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.sax.BoilerpipeSAXInput;


// Language detect librarys
import com.cybozu.labs.langdetect.*;

import net.arnx.jsonic.JSON;
import net.arnx.jsonic.JSONException;


import java.io.*;
import java.net.*;


import java.util.concurrent.Executors;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

class ExampleProgram {

  public static void main(String[] args) throws Exception {

EveryDetector evr = new EveryDetector();
InetSocketAddress addr = new InetSocketAddress("127.0.0.1",8080);
HttpServer server = HttpServer.create(addr, 0);

MyHandler hndl = new MyHandler();
hndl.setDetector(evr);

MyHandlerExtractContent hnd2 = new MyHandlerExtractContent();
hnd2.setDetector(evr);

MyHandlerDetectLanguage hnd3 = new MyHandlerDetectLanguage();
hnd3.setDetector(evr);

server.createContext("/",hndl);
server.createContext("/extractcontent",hnd2);
server.createContext("/detectlanguage",hnd3);
server.setExecutor(Executors.newCachedThreadPool());
server.start();
System.out.println("Server is listening on port 8080" );


 }
}

Source: https://github.com/remdex/boilerpipe-and-language-detect-api-server 来源: https : //github.com/remdex/boilerpipe-and-language-detect-api-server

How can I solve my problem? 我该如何解决我的问题?

Add public word before class ExampleProgram like here: class ExampleProgram之前添加public单词, class ExampleProgram所示:

public class ExampleProgram {
   public static void main(String[] args) throws Exception {

Please remember that the main class has to be always public . 请记住,主要班级必须总是public

Change class ExampleProgram to public class ExampleProgram , as the compiler has no way of locating the class with the main method. class ExampleProgram更改为public class ExampleProgram ,因为编译器无法使用main方法查找该类。

Note that you can only have one 'public' class, as otherwise would confuse the compiler. 请注意,您只能拥有一个“公共”类,否则将使编译器感到困惑。

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

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