I have a problem where by a section of my android app works fine on android version 4.1.2 but throws a NullPointerException when the same section is executed on android 4.4.3. My minimum sdk is set to 15 and target sdk is 21. Please find the code below:
try {
FileInputStream towe = new FileInputStream(path2);
re = new BufferedReader(new InputStreamReader(towe));
while ((res = re.readLine()) != null) {
result.append(res);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
re.close(); //ERROR IS GENERATED AT THIS LINE
} catch (IOException e) {
e.printStackTrace();
}
}
Morning guys, been away for a while. It turned out Exception was being thrown because of file path. I had hard-coded the path for android 4.1.2 but in 4.4.3 that path was different even though device was the same. I ended up using the
android.os.Environment.getExternalStorageDirectory();
method. Now working fine on both. Thanks for the suggestions