Home > Software engineering >  Getting no response for Retrofit GET request
Getting no response for Retrofit GET request

Time:11-26

I am beginner at Android development. Currently I am trying to implement simple API call with Open Weather API using Retrofit. Here is the code that doesn't go through:

var apiInterface:ApiInterface = getClient()!!.create(ApiInterface::class.java)
var call: Call<Example?>? = apiInterface.getWeatherData(tempName)

//after the call?.enqueue it shows me error down below

call?.enqueue(object : Callback<Example?> {
    override fun onResponse(call: Call<Example?>?, response: Response<Example?>) {
        try {
            Log.i("TAG", response.body()!!.main.toString())
            tempTemp = response.body()!!.main.temperature.toString()
            cityText.text = tempName
            currentTemperatureText.text = tempTemp
            descriptionText.text = response.body()!!.weather.description
            tempIcon = response.body()!!.weather.icon
            setIcon()

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun onFailure(call: Call<Example?>?, t: Throwable?) {}
})

D/TransportRuntime.SQLiteEventStore: Storing event with priority=DEFAULT, name=LE for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, DEFAULT, ) is already scheduled. Returning...
D/TransportRuntime.SQLiteEventStore: Storing event with priority=DEFAULT, name=LE for destination cct
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, DEFAULT, ) is already scheduled. Returning...
D/ActivityThread: Won't deliver top position change in state=4
D/ZrHung.AppEyeUiProbe: not watching, wait.
I/ple.weather_ap: Thread[7,tid=17770,WaitingInMainSignalCatcherLoop,Thread*=0x78ad12e400,peer=0x13a80198,"Signal Catcher"]: reacting to signal 3
I/ple.weather_ap: 
I/ple.weather_ap: Wrote stack traces to tombstoned
D/ZrHung.AppEyeUiProbe: restart watching
I/ZrHungImpl: sendRawEvent. wpId = 257
E/HiView.HiEvent: length is 0 or exceed MAX: 1024
D/DecorView: showOrHideHighlightView: hasFocus=true; winMode=1; isMrgNull=true
W/InputMethodManager: startInputReason = 1
W/HwRemoteInputMethodManager: isCasting false because IHwDistributedWindowManager is invalid.
I/ZrHungImpl: sendRawEvent. wpId = 258
D/DecorView: showOrHideHighlightView: hasFocus=false; winMode=1; isMrgNull=true
E/HiView.HiEvent: length is 0 or exceed MAX: 1024
E/HiView.HiEvent: length is 0 or exceed MAX: 1024
W/HwRemoteInputMethodManager: isCasting false because IHwDistributedWindowManager is invalid.
I/HwViewRootImpl: removeInvalidNode all the node in jank list is out of time
W/libEGL: EGLNativeWindowType 0x783ce57010 disconnect failed
W/ple.weather_ap: Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
D/ActivityThread: Remove activity client record, r= ActivityRecord{3af4548 token=android.os.BinderProxy@342c998 {com.example.weather_app/com.google.android.libraries.places.widget.AutocompleteActivity}} token= android.os.BinderProxy@342c998
I/ViewRootImpl: dispatchDetachedFromWindow in doDie
D/TransportRuntime.SQLiteEventStore: Storing event with priority=DEFAULT, name=LE for destination cct
E/RtgSchedManager: endActivityTransaction: margin state not match
D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, DEFAULT, ) is already scheduled. Returning...

I searched everywhere but couldn't find the solution. Thank you

CodePudding user response:

Create Empty class :

public class RetrofitResponse {

}

and use:

call?.enqueue(object : Callback<RetrofitResponse ?> {
override fun onResponse(call: Call<RetrofitResponse ?>?, response: Response<RetrofitResponse ?>) {
    try {
        Log.i("TAG", response.body()!!.main.toString())
        tempTemp = response.body()!!.main.temperature.toString()
        cityText.text = tempName
        currentTemperatureText.text = tempTemp
        descriptionText.text = response.body()!!.weather.description
        tempIcon = response.body()!!.weather.icon
        setIcon()

    } catch (e: Exception) {
        e.printStackTrace()
    }
}

override fun onFailure(call: Call<RetrofitResponse ?>?, t: Throwable?) {}

})

That problem from retrofit lib

  • Related