[SOLVED] Question Android Studio Kotlin API extraction using URL, throws a java.net.SocketException

Status
Not open for further replies.

Fleron

Honorable
Sep 9, 2014
25
0
10,530
Hey, so I'm trying to use URL from the java.net.URL, to read the data from an API as a string using URL like this;



response = URL("https://api.openweathermap.org/data/2.5/weather?q=$CITY&units=metric&appid=$API").readText()



anyway everything should be working, but while debugging I can see that it says "Method threw 'java.net.SocketException' exception. Anybody know what's wrong?



I heard something before about thread blocking?



Code:
override fun doInBackground(vararg params: String?): String? {



            var response:String?

            try{

                response = URL("https://api.openweathermap.org/data/2.5/weather?q=$CITY&units=metric&appid=$API").readText()

            }catch (e: Exception){

                response = null

            }

            return response

        }