java NameValuePair 的 Android Studio 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32831700/
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-11-02 20:50:52  来源:igfitidea点击:

Android Studio error with NameValuePair

javaandroid

提问by Mike K

Here's the bit of relevant code:

这是相关代码的位:

@Override
    protected Void doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("name", user.name));
        dataToSend.add(new BasicNameValuePair("age", user.age + ""));
        dataToSend.add(new BasicNameValuePair("username", user.username));
        dataToSend.add(new BasicNameValuePair("password", user.password));

        return null;
    }

It's telling me "Cannot resolve symbol NameValuePair" and the same thing for "BasicNameValuePair."

它告诉我“无法解析符号 NameValuePair”和“BasicNameValuePair”一样。

Is that syntax incorrect? Because I am pretty sure that both of those exist in Java.

那个语法不正确吗?因为我很确定这两者都存在于 Java 中。

Thanks in advance

提前致谢

回答by leonardkraemer

You need to import org.apache.commons.httpclient.NameValuePairand org.apache.http.message.BasicNameValuePairand add 'org.apache.httpcomponents:httpclient:4.5.1' to your gradle dependencies.

您需要导入org.apache.commons.httpclient.NameValuePairorg.apache.http.message.BasicNameValuePair添加 'org.apache.httpcomponents:httpclient:4.5.1' 到您的 gradle 依赖项中。