A JSON Parser developed by some members of the Android dev team. But a few weeks after completion of the parser, several methods became deprecated.
And when we use that parser, we get errors. Part of the stack trace is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[...] E/AndroidRuntime: Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1148) at java.net.InetAddress.lookupHostByName(InetAddress.java:405) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:251) at java.net.InetAddress.getAllByName(InetAddress.java:229) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) [...] |
Not sure if the NetworkOnMainThreadException
is being thrown because of the deprecated methods but the following code is what prevents our app from getting the error.
1 2 |
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); |