0

i tried to send an http request via android studio on java , and it gave me the error in the title , basiclly the program catches the program , can anyone help me please

P.S i gave the user premission for internet access

public class reader{
public static String get = null;
public static void run(){
    try {
        URL oracle = new URL("http://www.oracle.com/");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(oracle.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            Log.d("Ron", inputLine);
            get += inputLine;
        }
        in.close();
    }catch(Exception e){
        Log.d("Ron" , e.toString());
    }
}
DirtyAxe
  • 69
  • 1
  • 6
  • http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception – CommonsWare Jun 15 '16 at 15:57
  • To avoid downvote please next time please do a little research a little before asking on SO, – Hitesh Sahu Jun 15 '16 at 16:06
  • never mind i solved it , and the answer wasn't it , i just had to add this to my code : if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } – DirtyAxe Jun 15 '16 at 18:08

0 Answers0