Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用程序上缺少org/apache/http/client/methods/HttpUriRequest_Java_Android_Httpclient - Fatal编程技术网

Java Android应用程序上缺少org/apache/http/client/methods/HttpUriRequest

Java Android应用程序上缺少org/apache/http/client/methods/HttpUriRequest,java,android,httpclient,Java,Android,Httpclient,我正在尝试从我的Android应用程序中使用Telegrambot(4.4版,由于一些项目要求)。我实现了一个简单的bot,但当我尝试运行它时,出现以下错误: java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest at com.mypackage.Model.communication.remote.telegram.TelegramBotTest.initialize(Telegra

我正在尝试从我的Android应用程序中使用Telegrambot(4.4版,由于一些项目要求)。我实现了一个简单的bot,但当我尝试运行它时,出现以下错误:

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest

    at com.mypackage.Model.communication.remote.telegram.TelegramBotTest.initialize(TelegramBotTest.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
我试过了

compile 'org.apache.httpcomponents:httpclient-android:4.3.3'
但是没有成功。我必须包括哪些适当的依赖关系?以下是我为支持telegram而包含的依赖项:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.6'
compile 'org.telegram:telegrambots:2.4.4.5'
--更新: 我还收到了以下警告:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Warning:WARNING: Dependency org.json:json:20160810 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for release as it may be conflicting with the internal version provided by Android.

我是这样修好的。关于依赖项,我添加了以下内容:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile 'org.apache.httpcomponents:httpcore:4.4.6'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile files('libs/commons-logging-1.2.jar')    
compile "org.telegram:telegrambots:3.3"
configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    compile.exclude group: "commons-logging", module: "commons-logging"
}
在android部分中,我添加了以下内容:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile 'org.apache.httpcomponents:httpcore:4.4.6'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile files('libs/commons-logging-1.2.jar')    
compile "org.telegram:telegrambots:3.3"
configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    compile.exclude group: "commons-logging", module: "commons-logging"
}

现在,我能够执行TelegramBot代码,而不会出现运行时异常。

我已经用这种方式进行了修复。关于依赖项,我添加了以下内容:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile 'org.apache.httpcomponents:httpcore:4.4.6'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile files('libs/commons-logging-1.2.jar')    
compile "org.telegram:telegrambots:3.3"
configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    compile.exclude group: "commons-logging", module: "commons-logging"
}
在android部分中,我添加了以下内容:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile 'org.apache.httpcomponents:httpcore:4.4.6'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile files('libs/commons-logging-1.2.jar')    
compile "org.telegram:telegrambots:3.3"
configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    compile.exclude group: "commons-logging", module: "commons-logging"
}

现在,我能够执行TelegramBot代码而没有运行时异常。

堆栈跟踪表明您正在IDE中运行此代码。你试过用IntelliJ重新导入你的Gradle文件吗?@EvgenyTanhilevich是的,我成功了。仍然没有看到。你检查过这篇文章吗:?堆栈跟踪表明你是从IDE运行的。你试过用IntelliJ重新导入你的Gradle文件吗?@EvgenyTanhilevich是的,我成功了。还是没看到。你看过这篇帖子吗?