-2

I am trying to display a location point in map using static map API. This above link contains the image and I am trying to show this image in an ImageView. It throws NetworkOnMainThreadException. So I added these two lines

  StrictMode.ThreadPolicy policy = 
                     new StrictMode.ThreadPolicy.Builder()
                    .permitAll().build();
    StrictMode.setThreadPolicy(policy);

and now it works fine. But I want to know why NetworkOnMainThreadException.

Is there any other way to do this?

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Mithran
  • 301
  • 1
  • 3
  • 15
  • if you remove those lines you get NetworkOnMainThread Exception. If you try to google for this exception you will get tons of links explaining "why" and how to fix it – Blackbelt Dec 30 '13 at 13:02
  • did you try to look for NetworkOnMainThreadException? – Blackbelt Dec 30 '13 at 13:08

1 Answers1

0

You must use thread or asynctask if you will do network related operations. Check the most voted question about NetworkOnMainThreadException from this link

Community
  • 1
  • 1
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48