I get a very common crash below from the code below.
I thought my try, catches will have handled that.
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1102)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:65)
at java.io.InputStreamReader.<init>(InputStreamReader.java:65)
at com.test.test.FinderMain.grabPlaneRoute(FinderMain.java:759)
at com.test.test.FinderMain.access$7(FinderMain.java:729)
at com.test.test.FinderMain$GetRouteTask.doInBackground(FinderMain.java:684)
at com.test.test.FinderMain$GetRouteTask.doInBackground(FinderMain.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
Line 759 is within grabPlaneRoute and is the line containing the "StringBuilder total = new StringBuilder();"
Can someone help with this, it is driving me crazy! :-)
private void grabPlaneRoute(String adshex) {
List<GeoPoint> localList = new ArrayList<GeoPoint>();
HttpURLConnection con = null;
URL url;
InputStream is=null;
try {
url = new URL("http://www.testurl.com&test=" + adshex);
con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(20000 /* milliseconds */);
con.setConnectTimeout(60000 /* milliseconds */);
con.setRequestMethod("GET");
con.setDoInput(true);
// Start the query
con.connect();
is = con.getInputStream();
}catch (IOException e) {
//handle the exception !
e.printStackTrace();
return;
}
//localList = decodePoly(convertStreamToString(is));
//Log.i("HTTP DUMP", convertStreamToString(is));
BufferedReader r = new BufferedReader(new InputStreamReader(is),8024);
StringBuilder total = new StringBuilder();
String line;
try {
while ((line = r.readLine()) != null) {
String[] separated = line.split(",");
GeoPoint p = getPoint(Double.valueOf(separated[0]),Double.valueOf(separated[1]));
localList.add(p);
}
}catch (IOException e) {
//handle the exception !
e.printStackTrace();
}
drawPlaneRoute(localList);
}