我一直在阅读有关此错误的内容,而且我无法查看出错的地方。我将org.apache.httpcomponents.httpclient_4.5.2.jar添加到项目库,运行库和编译库中。
这是我的源代码:
public void HttpFunction()
{
try
{
String url = "http://www.google.com";
CloseableHttpClient client = HttpClients.createDefault();
HttpGet web_target = new HttpGet(url);
ResponseHandler<String> response_handler = new BasicResponseHandler();
String web_response = client.execute(web_target, response_handler);
System.out.println(web_response);
client.close();
}
catch (Exception no)
{
System.out.println("ERROR: " + no);
}
}
我确实拥有所有必需的导入,并且可以识别它们。这是它创建的巨大错误列表:
java.lang.NoClassDefFoundError: org/apache/http/HttpRequest
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
Exception in thread "main" C:\Users\JOE_LAPTOP\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED(总时间:0秒)
经过数天的研究和反复试验,我完全迷失了。请帮忙。