Ill say it again. THIS is the most powerful tutorial series of 2019. These cover it all, everything I use in a professional environment and most of the concepts needed for the foundation of a good application. Thank you! I Also have a TON of love amd respect for Florian and Mitch. They know who they are and I know Florian is working on a phenomenal series on Kotlin !
This video saved my semester!, I couldn´t understand how to use Retrofit till I found this one. Thank you so much for the great quality content. I will surely do the whole tutorial in the future :)
If people are still having issues getting a null error from the response, do the following: 1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset) 2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
Thank you very much! I usually do this in Java and am new to kotlin. Thank you for teaching me how to use retrofit with coroutines. You've gained a new sub !
Hi Reso Coder, Thank you for this tutorial. The retrofit2-kotlin-coroutines-adapter is Deprecated. will this tutorial be updated to make use of kotlin coroutines, suspend?
Reso Coder You should really provide a way for thankful watchers to express their gratitude, mate 😉 Your videos has literally saved my life (my job at least)
Привет, не было случайно проблем с генерацией ссылки в companion object { operator fun invoke(): WeatherStackApiService { val requestInterceptor = Interceptor { chain -> val url ??? У меня почему то ключ в концу ссылки приклеивает и соответственно запрос не обрабатывается =(
Getting an ERROR : java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String ***.CurrentWeatherEntry.toString()' on a null object reference My URL made by companion object in ApiService looks like this for some reason : api.weatherstack.com/current?query=London&language=en&access_key=56356555d5db9e0435606fa389bb504 Can not figure out why the key is at the end of the url and how to put it where it belongs Any ideas?
@@luizpaulo6169 I had the same problem , the reason was that the api changed a bit so key become access_key and q become query (key -> access_key), (q -> query)
thank you for this tutorial but i have a problem. When i run my program It crashes in line with "return@Interceptor chain.proceed(request)". Can anybody help?)
Hi. Https is not supported in freemode for APIX. Another thing is that the webpage is now called weatherstack. -If you follow this course be careful to update info
Thank you very much for your fabulous videos! I wanted to ask you which theme is the one that you have in Android Studio?? Thanks Regards from Argentina!
Guys, for who is getting null response, edit your CurrentWeatherResponse.kt, like that: import com.google.gson.annotations.SerializedName data class CurrentWeatherResponse( @SerializedName("current") val currentWeatherEntry: CurrentWeatherEntry, val location: Location, var request: Request ) Previously, the @SerializedName("current") was in the wrong line!
Love your tutorials! I am developing my own forecat app but with custom api and less functionalities. But I have some issue, maybe you will be able to help me. How can I get the api error request caught? (basically havig the same service a you)
I am following your tutorial, but in different case I trying to fetch JSON from API and its type is Array and I got error like this "com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $" can you help me?
Keep in mind that type of field named "precip" in your "CurrentWeatherEntry.kt" should be FLOAT (not integer)! I also didn't get that and got exception while get precip=0.1 in my response... i also send request to weatherstack to add data-type description of each field in response (to documentation).
I got the same issue as well, tried a few cities and the "current" field is always empty. I guess we will have to wait for APIXU to fix that and return to this later.
17 - 10 - 2019 API has also been updates. Sample : "api.weatherstack.com/current?access_key=API_KEY&query=CITY_NAME" HTTPS is giving an error. You must use HTTP. Because the API supports this. Be sure to include "android: usesCleartextTraffic =" true "in the manifest.xml file. Thanks.
See my comment a few minutes ago. 1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset) 2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
So frustrating that so much of this no longer works!! I have spent more time trying to figure why things are giving errors than actually coding. E.G; CoroutineCallAdapterFatory no longer exists and there is basically NO WAY of finding out how to sort it! EDIT; So I managed to fix this (???) by changing the code in ApiuxWeatherSevice.kt remove: .addCallAdapterFactory(CoroutineCallAdapterFatory()) and change from this: fun getCurrentWeatherAsync( @Query("q") location: String, @Query("lang") languageCode: String = "en" ): Deferred to: suspend fun getCurrentWeatherAsync( @Query("q") location: String, @Query("lang") languageCode: String = "en" ): CurrentWeatherResponse and change: val currentWeatherResponse = apiService.getCurrentWeatherAsync("Leeds").await() to: val currentWeatherResponse = apiService.getCurrentWeatherAsync("Leeds")
I am facing same issue but even after applying the solution provided by you my app is crashing "Unable to create call adapter for kotlinx.coroutines.Deferred'
See my comment a few minutes ago. 1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset) 2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
There are changes made since the video is posted 1. Apixu is no longer available and changes to weatherstack and also since android 28, you cannot access http by default Solution : - Look at nehank poilkar and Marshall Borsos comment 2. Since Retrofit 2.6, coroutine call adapter is deprecated Solution : - Look at Jamie Lindsey comment, but keep in mind that query parameter is changed to the solution no.1 3. If you get an error saying java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method... Solution : - You need to add this code: compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } under buildTypes in your build.gradle(app) file 4. Ensure data type for each variable, since we auto-generate the data class using plugin These are the steps I did to make this tutorial works
Another thin. for the call to the api. " api.apixu.com/v1/current.json?key=89e8bd89085b41b7a4b142029180210&q=London&lang=en" there are several parameter you have to change as current.jason -> current q-->query., key-> key_code . Another thing, Serialized didn´t work for me
the most important part of the Coroutines was skipped, and don't tell me there is another course for Coroutines because it doesn't tell how to deal with Coroutines in android environment
Reset the first API key the web site gives you. That's what I did and it worked for me after they gave me a second key. The first key they gave me wasn't valid for some reason (according to their error message). Then, test your app using this URL below inserting your API key between the '=' sign and the '&' sign api.weatherstack.com/current?access_key=INSERTAPIKEYHERE&query=New%20York or better yet, just change your API to weatherapi.com, weatherapi.com supports HTTPS apparently, and weatherstack.com doesn't unless you pay.
Thank you for the awesome Weather app tutorial. How to send @FormUrlEncoded for post request. and also how to send @Header while creating interceptor for example @POST("api/v1/login") @FormUrlEncoded fun login( @Field("username") email: String, @Field("password") password: String ): Deferred I'm trying this but backend not receiving these form fields
If you get CLEAR TEXT ERROR, lock at this solution stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted, it worked for me.
Ill say it again.
THIS is the most powerful tutorial series of 2019.
These cover it all, everything I use in a professional environment and most of the concepts needed for the foundation of a good application.
Thank you!
I Also have a TON of love amd respect for Florian and Mitch. They know who they are and I know Florian is working on a phenomenal series on Kotlin !
Mitch is Nice and so the Walther
The url for fetching weather has changed
As cheryl posted :
For new API:
@GET("current")
fun getCurrentWeather(
@Query("query") location: String,
@Query("lang") languageCode: String = "en"
):Deferred
companion object{
operator fun invoke():ApixuWeatherApiService{
val requestInterceptor = Interceptor { chain->
val url = chain.request()
.url()
.newBuilder()
.addQueryParameter("access_key", API_KEY)
.build()
val request = chain.request()
.newBuilder()
.url(url)
.build()
return@Interceptor chain.proceed(request)
}
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(requestInterceptor)
.build()
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl("api.weatherstack.com/")
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApixuWeatherApiService::class.java)
}
Plus Android 8 does not allows url with only "http"
Solution :
Step 1- add this entry in manifest
Step 2 - and:
create res/xml/network_security_config.xml
It worked for me..!! Cheers
Thank you bro :D
thx
Thanks!
Thank you! :)
Wow that json to kotlin class plugin is really really helpful. Thank you very much.
Just be careful of the types it automatically assigns, for example it may get confused between Int and Double very easily.
I am still going through this tutorial. This is definitely the best android tutorial on TH-cam. You are a hero.
This video saved my semester!, I couldn´t understand how to use Retrofit till I found this one.
Thank you so much for the great quality content. I will surely do the whole tutorial in the future :)
seriously, Are you guys having retrofit in syllabus?
@@timelord404 Hahahaha
If people are still having issues getting a null error from the response, do the following:
1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset)
2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
I am getting null will try it solution. Thanks
thanks Step 1 did the trick
I just found how to fix this, and you don't need to reply my question, you tutorials are helpful for us
Thank you very much! I usually do this in Java and am new to kotlin. Thank you for teaching me how to use retrofit with coroutines.
You've gained a new sub !
Really thanks. You saved my life and time…
Hi Reso Coder, Thank you for this tutorial. The retrofit2-kotlin-coroutines-adapter is Deprecated. will this tutorial be updated to make use of kotlin coroutines, suspend?
You saved me best tutor ever!
You are a really skilled teacher.
Wow! That really interesting and simple guide about Retro + Weather + Kotlin + VM.
Thanks for explanation in the ApiService!
Very good tutorial! It turns out I was doing alot of things the wrong way. Looking forward to future tutorials!
This tutorial is the best gift for Christmas! Thanks!
I'm really happy I could help you!
very helpful! thank you
Bro you're the best
Brilliant! Is there a Patreon so we can donate to keep the tutorials coming?
Not yet 😉 Thanks though!
@@ResoCoder Hope you reach 100k subs soon!
Reso Coder
You should really provide a way for thankful watchers to express their gratitude, mate 😉
Your videos has literally saved my life (my job at least)
Greate lesson - Thx man!!
Привет, не было случайно проблем с генерацией ссылки в
companion object {
operator fun invoke(): WeatherStackApiService {
val requestInterceptor = Interceptor { chain ->
val url ???
У меня почему то ключ в концу ссылки приклеивает и соответственно запрос не обрабатывается =(
Thanks man, Waiting for the next tutorial in this series 🔥
Getting an ERROR :
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String ***.CurrentWeatherEntry.toString()' on a null object reference
My URL made by companion object in ApiService looks like this for some reason :
api.weatherstack.com/current?query=London&language=en&access_key=56356555d5db9e0435606fa389bb504
Can not figure out why the key is at the end of the url and how to put it where it belongs
Any ideas?
im facing the same problem
put in yout
Solved!
put in your Mnifest
@@luizpaulo6169 I had the same problem , the reason was that the api changed a bit so key become access_key and q become query (key -> access_key), (q -> query)
Awesome Tutorial Reso Coder.. keep it up
Hi can you tell me why return@Interceptor ? chain-> is this return return@Interceptor?
thank you for this tutorial but i have a problem. When i run my program It crashes in line with "return@Interceptor chain.proceed(request)". Can anybody help?)
amazing tutorial, thanks so much for spending your time on these tutorials.
Really great tutorial .. waiting for next tutorial
for what annotation used for in android??is this doing anything in the code flow or just a metadata
Hi. Https is not supported in freemode for APIX. Another thing is that the webpage is now called weatherstack. -If you follow this course be careful to update info
Děkuji.
Thank you very much for your fabulous videos! I wanted to ask you which theme is the one that you have in Android Studio??
Thanks
Regards from Argentina!
Material Theme UI Darker
Hello reso, can you tell me how to protect our Api keys and our App in general from reverse engineering ? (Other ways than Proguard )
How come you are not using Moshi instead of Gson? I've heard it's better for Android/Kotlin
Guys, for who is getting null response, edit your CurrentWeatherResponse.kt, like that:
import com.google.gson.annotations.SerializedName
data class CurrentWeatherResponse(
@SerializedName("current")
val currentWeatherEntry: CurrentWeatherEntry,
val location: Location,
var request: Request
)
Previously, the @SerializedName("current") was in the wrong line!
Great tutorial as always. Thanks
Very good one. Thanks.
Love your tutorials! I am developing my own forecat app but with custom api and less functionalities. But I have some issue, maybe you will be able to help me.
How can I get the api error request caught? (basically havig the same service a you)
I am following your tutorial, but in different case I trying to fetch JSON from API and its type is Array and I got error like this
"com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $" can you help me?
I had to change precipMm to a double for app to work in CurrentWeatherEntry.
where is request success / fail part?
Keep in mind that type of field named "precip" in your "CurrentWeatherEntry.kt" should be FLOAT (not integer)!
I also didn't get that and got exception while get precip=0.1 in my response... i also send request to weatherstack to add data-type description of each field in response (to documentation).
pressure also "Float"
Please help the Apixu Api is not working
I'm not getting the currentWeather data on response json it always return empty. Am i missing a step? Help!
I got the same issue as well, tried a few cities and the "current" field is always empty. I guess we will have to wait for APIXU to fix that and return to this later.
Hey bro use Paris instead, its working -> &q=Paris
Thank you bro I think they have fixed it it's working now🤟
this tutorial only give one location which is london? what if i need to choice place and parse json?
It's only the second part of this series. Later on we'll implement custom location.
please set the link of kotlin Coroutines tutorial in video description so that we can get it by easy way a can't get the link yet , thanks in advance
17 - 10 - 2019
API has also been updates.
Sample : "api.weatherstack.com/current?access_key=API_KEY&query=CITY_NAME"
HTTPS is giving an error.
You must use HTTP. Because the API supports this.
Be sure to include "android: usesCleartextTraffic =" true "in the manifest.xml file.
Thanks.
i have a problem with "return@Interceptor chain.proceed(request)"
when i run my app , it crashes
+1
What theme do you use in Android Studio?
Material Theme UI
Very nice
awesome, thanks!
It all doesn't work. The project on Github is also not working. The problem is getting a response from the API.
I have to use weatherstack.com and i have CurrentWeatherResponse(location=null, CurrentWeatherEntry=null) on Emulator. Can you help me?
they changed the api. Try with this code ;)
@GET("current")
fun getCurrentWeather(
@Query("query") location: String,
@Query("lang") language: String = "en"
): Deferred
//equal to static methods
// 15:15 - 22:06 --> Part2
companion object {
operator fun invoke(): ApixuWeatherAPIService {
val requestInterceptor = Interceptor { chain ->
val url = chain.request().url()
.newBuilder().addQueryParameter("access_key", API_LEY).build()
val request = chain.request().newBuilder().url(url).build()
return@Interceptor chain.proceed(request)
}
val okHttpClient = OkHttpClient.Builder().addInterceptor(requestInterceptor).build()
return Retrofit.Builder().client(okHttpClient).baseUrl("api.weatherstack.com/")
.addCallAdapterFactory(CoroutineCallAdapterFactory()).addConverterFactory(GsonConverterFactory.create()).build().create(ApixuWeatherAPIService::class.java)
}
}
me too
@@RafaelDuarte thank you
@@zoranjankovic4708 👊
Sadly, im getting null pointer exception on response.toString() =/
See my comment a few minutes ago.
1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset)
2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
If you have problem nullexception or cleartexttraffic then add android:usesCleartextTraffic="true"
to your manifest file
How did you get Android Studio to look like that?
MaterialUi Theme plugin
thanks
So frustrating that so much of this no longer works!! I have spent more time trying to figure why things are giving errors than actually coding.
E.G;
CoroutineCallAdapterFatory no longer exists and there is basically NO WAY of finding out how to sort it!
EDIT;
So I managed to fix this (???) by changing the code in ApiuxWeatherSevice.kt
remove:
.addCallAdapterFactory(CoroutineCallAdapterFatory())
and change from this:
fun getCurrentWeatherAsync(
@Query("q") location: String,
@Query("lang") languageCode: String = "en"
): Deferred
to:
suspend fun getCurrentWeatherAsync(
@Query("q") location: String,
@Query("lang") languageCode: String = "en"
): CurrentWeatherResponse
and change:
val currentWeatherResponse = apiService.getCurrentWeatherAsync("Leeds").await()
to:
val currentWeatherResponse = apiService.getCurrentWeatherAsync("Leeds")
The example I just tried worked ok. Maybe versioning issues
@@andrewtittle9130 first notice that don't use "q" because the current url has something different.
I am facing same issue but even after applying the solution provided by you my app is crashing
"Unable to create call adapter for kotlinx.coroutines.Deferred'
java.lang.IllegalArgumentException: Could not locate call adapter for class java.lang.Object.
good tutorial but give me back all null. Does anyone know what the problem is....current_text.text = currentWeatherResponse.toString()
See my comment a few minutes ago.
1. In ApixuWeatherApiService.kt, remove @Query("language") languageCode: String = "en". The current version of WeatherStack does not support foreign languages on the free plan, and English uses no language code (unset)
2. Follow the instructions given by nehank poilkar to ensure you do not have issues related to the new parameter nomenclature and due to the fact that Android Studio by default does not allow access to the internet or non-HTTPS resources
1.25x speed is best for these video.
Nice tutorial but there is no seperation of concerns.
Followed the whole tutorial .still my app is getting crashed.can anyone help me?
There are changes made since the video is posted
1. Apixu is no longer available and changes to weatherstack and also since android 28, you cannot access http by default
Solution :
- Look at nehank poilkar and Marshall Borsos comment
2. Since Retrofit 2.6, coroutine call adapter is deprecated
Solution :
- Look at Jamie Lindsey comment, but keep in mind that query parameter is changed to the solution no.1
3. If you get an error saying java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method...
Solution :
- You need to add this code:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
under buildTypes in your build.gradle(app) file
4. Ensure data type for each variable, since we auto-generate the data class using plugin
These are the steps I did to make this tutorial works
Another thin. for the call to the api. " api.apixu.com/v1/current.json?key=89e8bd89085b41b7a4b142029180210&q=London&lang=en" there are several parameter you have to change as current.jason -> current q-->query., key-> key_code . Another thing, Serialized didn´t work for me
you Tutorials are very helpful, but in this video you didn't explain retrofit enough. :(
the most important part of the Coroutines was skipped, and don't tell me there is another course for Coroutines because it doesn't tell how to deal with Coroutines in android environment
Well, we'll come back to coroutines later on. For example in the part which I'm releasing this Saturday and also in later parts.
app crashes after doing this second video
Reset the first API key the web site gives you. That's what I did and it worked for me after they gave me a second key. The first key they gave me wasn't valid for some reason (according to their error message). Then, test your app using this URL below inserting your API key between the '=' sign and the '&' sign api.weatherstack.com/current?access_key=INSERTAPIKEYHERE&query=New%20York or better yet, just change your API to weatherapi.com, weatherapi.com supports HTTPS apparently, and weatherstack.com doesn't unless you pay.
Thank you for the awesome Weather app tutorial. How to send @FormUrlEncoded for post request. and also how to send @Header while creating interceptor
for example
@POST("api/v1/login")
@FormUrlEncoded
fun login(
@Field("username") email: String,
@Field("password") password: String
): Deferred
I'm trying this but backend not receiving these form fields
IDE font size and Editor font size is too small. it's not best way for Make a course
Umm, excuse me? Is the font size of 26 small for you? Android studio UI cannot be scaled.
Eating watermelon has never been this technical.
Need to change from deferred to suspend in retrofit 2.6.0
github.com/square/retrofit/blob/master/CHANGELOG.md#version-260-2019-06-05
I'm still receiving NULL despite of everything advices given by those in the comments...
If you get CLEAR TEXT ERROR, lock at this solution stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted, it worked for me.
I can't understand from you because you explain so difficult
Awful diction