i'm trying to fix the NetworkOnMainThreadException, here is my class located in a library
class CoinProvider(private val context: Context, isTestnet: Boolean) {
val result = URL("http://mylink.com/file.json").readText()
val result1 = URL("http://mylink.com/file1.json").readText()
private val filename: String = if (!isTestnet) (result) else (result1)
fun defaultCoins(): CoinResponse {
return CoinResponse.parseFile(context, filename)
}
}
when i try to add this to my class
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
i got this " expecting member declaration "
the code above can be added to the MainActivity of the project but it doesn't do anything because i want to fix the NetworkOnMainThreadException on the library not in the project.
how can i fix the issue in this kotlin library?