Code first:
AssetManager mgr = DeviceListActivity.this.getApplicationContext().getAssets();
try {
Log.e("Glenn:", address);
FileOutputStream fout = mgr.openFd("device/device_address.txt").createOutputStream();
PrintWriter _fout = new PrintWriter(fout);
_fout.println(address);
Log.e("Glenn", address);
_fout.close();
fout.close();
InputStream fin = mgr.open("device/device_address.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
address = br.readLine();
try {
Log.e("Glenn:", address);
} catch (NullPointerException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
Log.e("Glenn", "error with OutputStream");
}
The value of address printed by the first two Log.e()
calls is the right value, which actually is a device MAC address. However, when I was trying to test the value of address read from the file, which had just been written, NullPointerException
has been caught within the Log.e()
call. This means the value read from the file is NULL
. Can anyone point out what's wrong with the code?