本文介绍了无法在 android 中解析符号“Defaulthttpclient"和“Httppost"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个新项目.但我有一个小问题.即使我已经在我以前的项目中使用了 DefaultHttpClientHttpPost,我也无法使用它.

i build a new project.but i have a little problem.i can't use DefaultHttpClient and HttpPost even after i use it in my previous project already.

是否需要添加任何外部库?

Is there any external librery i have to add?

我不知道如何同时使用这两个.

i don't know how can i use both of this.

帮我解决这个问题.

我的 build.gradle

My build.gradle

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "22.0.1"

        defaultConfig {
            applicationId "Id"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile files('libs/httpcore-4.3.3.jar')
        compile files('libs/httpmime-4.3.6.jar')
    }

提前致谢........

Thanks in advance.........

推荐答案

jars 中有两种不同的 DefaultHttpClient 类,你导入错了,
从你的类文件中删除 DefaultHttpClient 的导入,并添加这个,

There are two different DefaultHttpClient classes are available in the jars, you imported the wrong one,
Remove the import of DefaultHttpClient from your class file, and add this one,

import org.apache.http.impl.client.DefaultHttpClient;

还有一点,不应该是HttpPost,应该是HttpClient完整示例,

One more thing, It should not be HttpPost, it will be HttpClientcomplete example,

import org.apache.http.impl.client.DefaultHttpClient;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost();

这篇关于无法在 android 中解析符号“Defaulthttpclient"和“Httppost"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 03:34