in my app I have to "download" a string from a file and when user disables internet and the app is open with AsyncTask operation it crashes because the internet operation doesn't work and the error flows in IOException catch. I tried to do an operation in catch(IOException e) but it seem to doesn't work because app crash anyway. How can I avoid my app to crash? Code:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(MegaMethods.url + MegaMethods.BuildSelectedPath + "_Link.txt").openStream()));
String line = reader.readLine();
for (int k = 0; k < params[0] ; k++) {
line = reader.readLine();
}
return line;
}catch (IOException e){
e.printStackTrace();
Log.i("IOEXCEPTION", "");
MegaMethods Errorr = new MegaMethods();
Errorr.Back();
Errorr.Error();
}
Logcat
01-06 23:07:59.389 14512-14512/sparkyka.it.pcbuilds E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{sparkyka.it.pcbuilds/sparkyka.it.pcbuilds.Office}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
I don't want to check internet connection, if internet operation doesn't work correctly I want to avoid app to crash and do stuff