Java 无法解析符号 NameValuePair

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32121031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:03:38  来源:igfitidea点击:

Cannot resolve symbol NameValuePair

javaandroidsdk

提问by g8214435

In my project I got an error:

在我的项目中,我遇到了一个错误:

Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

检索项目的父项时出错:找不到与给定名称“android:TextAppearance.Material.Widget.Button.Inverse”匹配的资源。

Then I tried to fix it use this:

然后我尝试修复它使用这个:

compileSdkVersion 23

But then I got error:

但后来我得到了错误:

cannot resolve symbol NameValuePair android

无法解析符号NameValuePair android

How to fix this error?

如何修复此错误?

采纳答案by Blackbelt

NameValuePairis part the package org.apachewhich was deprecated with Android 22and removed with Android M, which is the version against you are compiling. What is interesting is that neither the documentation of NameValuePairis reachable

NameValuePairorg.apache被弃用Android 22和删除的包的一部分Android M,这是针对您正在编译的版本。有趣的是,NameValuePair的文档都无法访问

回答by Byron Kiriibwa

I was facing the same issue. To resolve it, I used:

我面临着同样的问题。为了解决它,我使用了:

import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.message.BasicNameValuePair;

and also added

并且还添加了

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "cz.msebera.android:httpclient:4.4.1.1"
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'

to the app/gradle dependencies. I hope that helps

到应用程序/gradle 依赖项。我希望有帮助

回答by Rahul Sharma

If you want to use NameValuePairor BasicNameValuePairin android studio with latest API Levels. Then follow steps below:

如果您想在具有最新 API 级别的 android studio 中使用NameValuePairBasicNameValuePair。然后按照以下步骤操作:

  • Open build.gradle(Module) file and copy these dependencies:

    implementation 'com.google.http-client:google-http-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-gson:+'
    
  • Copy useLibrary 'org.apache.http.legacy'below buildToolsVersionlike:

    android {
    useLibrary 'org.apache.http.legacy'}
    
  • 打开 build.gradle(Module) 文件并复制这些依赖项:

    implementation 'com.google.http-client:google-http-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-gson:+'
    
  • 复制useLibrary 'org.apache.http.legacy'如下buildToolsVersion

    android {
    useLibrary 'org.apache.http.legacy'}
    

Thats all. Now just sync gradle file.

就这样。现在只需同步 gradle 文件。

Note:In dependencies i recommend to use latest version of libraries instead of + symbol.

注意:在依赖项中,我建议使用最新版本的库而不是 + 符号。

回答by D??ish Sh?rmà

Today i also had same problem. I solved with two changes in my build.gradle

今天我也遇到了同样的问题。我在 build.gradle 中解决了两个更改

 1)   android {
        useLibrary 'org.apache.http.legacy'
              }

2)  compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'

My final build.gradle file:

我的最终 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

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

android {
    useLibrary 'org.apache.http.legacy'
}
dependencies
        {
            compile fileTree(include: ['*.jar'], dir: 'libs')
            testCompile 'junit:junit:4.12'
            compile 'com.android.support:appcompat-v7:23.2.0'
            compile 'com.android.support:recyclerview-v7:23.0.+'
            compile 'org.apache.httpcomponents:httpcore:4.4.1'
            compile 'org.apache.httpcomponents:httpclient:4.5'

        }

回答by test Android

add this:

添加这个:

compile'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

in app based build.gradle it will pick it up

在基于 app 的 build.gradle 中它会捡起来

回答by Abhishek Jain

Had the same problem

有同样的问题

Solved it as follows:

解决了如下:

  1. Add this in dependencies:
  1. 在依赖项中添加这个:

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

编译组:'org.apache.httpcomponents',名称:'httpclient-android',版本:'4.3.5.1'

  1. Add this below targetSdkVersion in defaultConfig
  1. 在 defaultConfig 中的 targetSdkVersion 下面添加这个

useLibrary 'org.apache.http.legacy'

useLibrary 'org.apache.http.legacy'

回答by Klim Letov

Nested class would work:

嵌套类可以工作:

private class NameValuePair {
        private String mName;
        private String mValue;

        public NameValuePair(String name, String value) {
            mName = name;
            mValue = value;
        }

        public String getName() {
            return mName;
        }

        public String getValue() {
            return mValue;
        }
    };