android - 导入已在单一类型导入中定义

标签 android import response

我需要帮助来弄清楚如何解决我的 Activity 中两个相互冲突的导入的问题,即:

  1. retrofit2.Response
  2. com.android.volley.Response

第一个导入是为了帮助我管理 api 回调响应,而第二个是为了帮助我在上传文件时管理 stringrequest 响应。单独实现一个,即仅运行 api 调用来获取数据,它自己就可以正常工作,就像自己上传文件一样。现在将两者合并为一个 Activity ,这样当用户从下拉列表中选择数据(其列表来自服务器)并随后上传文件时,事实证明获取错误非常麻烦:

retrofit2.Response already defined in single type import

com.android.volley.Response already defined in single type import

取决于哪个先到。

最佳答案

在 Java 中,您不能导入两个具有相同名称的不同类。在这些情况下,您可以导入一个,但使用具有完全限定名称的另一个。

例如:

import retrofit2.Response;


Response response = ...; //This is Retrofit Response object
com.android.volley.Response otherResponse = ...; //This is volley Response object

编辑:

在 Kotlin 中,您可以通过分配别名来导入

import retrofit2.Response as RResponse
import com.android.volley.Response as VResponse


val response: RResponse = ... //This is Retrofit Response object
val otherResponse: VResponse = ... //This is volley Response object

关于android - 导入已在单一类型导入中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56205609/

相关文章:

从源代码构建的 android 模拟器无法启动

java - 获取要加载的类所需的类列表

perl - 在 Raku 中使用 Perl 5 模块 Data::Printer 的 `show_tied` 选项时,如何关闭它?

ajax - jQuery 1.5.2 显示空响应的 [object XMLDocument]

android - 通过 NDK 将数据从 OpenCV Mat 复制到 Surface 会产生小错误。

php - 需要 php 代码才能使用 ACS 在 Android 设备上发送推送通知

安卓截图

python - Scapy 模块阻止 PyCharm 调试器

PHP Curl 异步响应

javascript - 如何在 Rails 中的 Controller 操作成功或失败的 View 中显示 JSON 状态消息?