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
Android Studio error with NameValuePair
提问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.NameValuePair
and org.apache.http.message.BasicNameValuePair
and add 'org.apache.httpcomponents:httpclient:4.5.1' to your gradle dependencies.
您需要导入org.apache.commons.httpclient.NameValuePair
并org.apache.http.message.BasicNameValuePair
添加 'org.apache.httpcomponents:httpclient:4.5.1' 到您的 gradle 依赖项中。