最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【无需解决】Java代码new BasicNameValuePair时出错:The constructor BasicNameValuePair(String, boolean) is undefined

Java crifan 4815浏览 0评论

【问题】

折腾:

【教程】模拟登陆百度之Java代码版

期间,用如下代码:

            List<NameValuePair> cookieNamePairList = new ArrayList<NameValuePair>();
            cookieNamePairList.add(new BasicNameValuePair("BDUSS", false));
            cookieNamePairList.add(new BasicNameValuePair("PTOKEN", false));
            cookieNamePairList.add(new BasicNameValuePair("STOKEN", false));
            cookieNamePairList.add(new BasicNameValuePair("SAVEUSERID", false));

结果出错:

The constructor BasicNameValuePair String boolean is undefined

即:

The constructor BasicNameValuePair(String, boolean) is undefined

【解决过程】

1.很明显,此处的BasicNameValuePair,不支持:

(String, boolean)

类型。

而只支持:

(String, String)

2.参考:

android how to send int and double as namevaluepair as http post

没用。

3.搜:

NameValuePair BasicNameValuePair

而找到:

得知:

Class BasicNameValuePair

有几种实现:

Serializable, Cloneable, NameValuePair

4.再去看对应的:

Interface NameValuePair

结果没有找到除了BasicNameValuePair之外的,可以支持(String, boolean)的实现。

5.参考了:

Code Examples of BasicNameValuePair

推测:

貌似NameValuePair中,就没有支持(String, boolean)的实现。

6.而自己此处的本意是:

实现一个(String,boolean)类型的Dict

所以,再想办法去:

【已解决】Java中实现{String, boolean}类型的字典Dict变量

 

【总结】

最终,是没有解决此处的:

The constructor BasicNameValuePair(String, boolean) is undefined

而换个方式,实现了Dict,得以实现类似的{String,boolean}的效果的。

转载请注明:在路上 » 【无需解决】Java代码new BasicNameValuePair时出错:The constructor BasicNameValuePair(String, boolean) is undefined

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.172 seconds, using 22.14MB memory