Quantcast
Viewing latest article 42
Browse Latest Browse All 191

Answer by Dipak Keshariya for How can I fix 'android.os.NetworkOnMainThreadException'?

There are two solutions of this problem.

  1. Don't use a network call in the main UI thread. Use an async task for that.

  2. Write the below code into your MainActivity file after setContentView(R.layout.activity_main);:

    if (android.os.Build.VERSION.SDK_INT > 9) {StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();StrictMode.setThreadPolicy(policy);}

And the below import statement into your Java file.

import android.os.StrictMode;

Viewing latest article 42
Browse Latest Browse All 191

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>