import already defined in single type import
Asked Answered
P

3

11

I need help to figure out how to solve an issue on two conflicting imports in my activity namely:

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

the first import is meant to help me manage api callback responses while the second is meant to help me manage stringrequest response when uploading files. Implenting one alone i.e just running api calls to get data works fine on its own just like uploading files on their own is fine. Now merging the two in one activity such that when a user selects data from a dropdown whose list is sourced from a server and later upload a file has proved to be very troublesome getting the error:

retrofit2.Response already defined in single type import

or

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

depending on which one comes first.

Pancho answered 19/5, 2019 at 7:22 Comment(0)
B
1

If I were you I would create use retrofit to do the image uploading check How to Upload Image file in Retrofit 2 and ANDROID UPLOAD IMAGE TO SERVER USING RETROFIT 2

Barbra answered 19/5, 2019 at 7:32 Comment(0)
G
16

In Java, you cannot import two different classes with the same name. In these situations, you can import one, but use the other with a fully qualified name.

For example:

import retrofit2.Response;


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

Edit:

In Kotlin you can import by assigning an alias

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

Gravimeter answered 19/5, 2019 at 7:43 Comment(0)
H
4

If you need to use two or more classes with same name, you can pick either of the option.

Option-1: Use one type with import and use the other’s fully qualified class name.

import java.util.Date;

public class SameNameConflicts {
    Date date;
    java.sql.Date sqlDate;
}

Option-2: Use fully qualified class name for both.

public class SameNameConflicts {
    java.util.Date date;
    java.sql.Date sqlDate;
}
Hunter answered 2/3, 2021 at 12:9 Comment(0)
B
1

If I were you I would create use retrofit to do the image uploading check How to Upload Image file in Retrofit 2 and ANDROID UPLOAD IMAGE TO SERVER USING RETROFIT 2

Barbra answered 19/5, 2019 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.