My app crashes when I do any networking activities (specifically, reading text through an InputStream), but only on Android Pie. I've tried it using emulators running various API versions, but this only happens on API 28. I have also tried this on an actual phone running Pie, and it crashes there as well. The app runs fine on all other Android versions afaik.
The logcat shows this:
2018-12-09 14:59:16.917 6864-6925/<package> E/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: <package>, PID: 6864
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at <package>.<Activity class>.<method>(<Activity class>.java:304)
The statement that the stack trace leads to in my code is:
BufferedReader br = new BufferedReader(new InputStreamReader(text));
where text = con.getInputStream();
up above, which when I debugged, was returning null
. con
is a URLConnection
that opens a connection to a particular URL. The value of con
seems alright and is identical to con
values on different API versions.
So, the culprit seems to be text = con.getInputStream();
which is returning normally on API 27 and below, but is returning null
on Pie.
Any idea what could be causing this? Let me know if there's any more information I could provide.