【问题标题】:JsonObjectRequest ambiguous constructor usage errorJsonObjectRequest 不明确的构造函数使用错误
【发布时间】:2016-03-02 19:23:18
【问题描述】:

这是错误信息:

Error:(56, 42) 错误:对 JsonObjectRequest 的引用不明确 构造函数 JsonObjectRequest(int,String,String,Listener,ErrorListener) 在 JsonObjectRequest 和构造函数中 JsonObjectRequest(int,String,JSONObject,Listener,ErrorListener) 在 JsonObjectRequest 中匹配

查看附图:

【问题讨论】:

  • 因为您发送 null 它可以是 String 或 JSONObject 所以编译器无法决定调用哪个构造函数..
  • 我不明白它在我朋友的电脑上运行,但我收到错误,可能是 android studio 吗?

标签: android json android-volley


【解决方案1】:

com.android.volley.toolbox.JsonObjectRequest 有两个类似的构造函数,有 5 个参数:

1

public JsonObjectRequest(int method, String url, String requestBody, Listener<JSONObject> listener, ErrorListener errorListener)

2

public JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) {

如果给第三个参数传递null,就无法检测到你要使用哪个构造函数。 requestBody 为 null 还是 jsonRequest 为 null?

你最好使用另一个构造函数:

public JsonObjectRequest(int method, String url, Listener<JSONObject> listener, ErrorListener errorListener)

或者在你的 volley 版本中应该是:

public JsonObjectRequest(int method, String url, Listener<JSONObject> listener)

或者你可以尝试设置第三个参数;

1

使用空字符串(如“”)使用第一个构造函数。

2

使用空但 JSONObject 的实例(例如 new JSONObject())来使用第二个构造函数。

编辑:我猜你使用的是旧版本的 volley。在 1.0.19 版本中,ErrorListener 被添加到构造函数中。因此,我回答的构造函数是您的更高版本。但想法是一样的。

【讨论】:

  • 我的凌空编译'com.mcxiaoke.volley:library:1.0.19'
猜你喜欢
  • 1970-01-01
  • 2020-11-25
  • 2017-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多