【问题标题】:incompatible types: ArrayList<BasicNameValuePair>?不兼容的类型:ArrayList<BasicNameValuePair>?
【发布时间】:2017-11-24 13:58:47
【问题描述】:

我问了问题here。现在我可以将arraylist 传递给另一个活动。

在我的第二个活动中,我试图发布这个数组列表。

ArrayList<com.example.ss.myapp.BasicNameValuePair> testing = this.getIntent().getParcelableArrayListExtra("extraextra");

 HttpClient httpclient1 = new DefaultHttpClient();
                        HttpPost httppost1 = new HttpPost(url);
                        httppost1.setEntity(new UrlEncodedFormEntity((List<? extends org.apache.http.NameValuePair>) testing));

我收到一个错误:incompatible types: ArrayList&lt;BasicNameValuePair&gt; cannot be converted to List&lt;? extends NameValuePair&gt;

如何将ArrayList&lt;com.example.ss.myapp.BasicNameValuePair&gt; testing 转换为ArrayList&lt;NameValuePair&gt; testing

【问题讨论】:

  • 到目前为止,您的代码看起来不错,但为了使这种转换成为可能,BasicNameValuePair 必须扩展 NameValuePair。你能仔细检查一下吗?
  • 谢谢,当我这样做时,它会起作用。 @lulian Popescu

标签: java android arraylist basicnamevaluepair


【解决方案1】:

NameValuePair 应该指的是这个link。根据您的链接,您的课程不会扩展NameValuePair。为此,您需要更改代码:

 public class BasicNameValuePair extends NameValuePair implements Parcelable {

并根据需要/需要实现/覆盖所有必要的方法。

【讨论】:

    猜你喜欢
    • 2014-09-07
    • 2012-10-19
    • 2013-08-30
    • 2013-10-29
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多