hey when i create a file the logs show that file is created but it not existed in system, and while writing into that file it says null pointer exception is there anyone can help me please
try {
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath()+ "/Sniffiing");
dir.mkdirs();
File file1 = new File(dir,"dump1.txt");
file1.createNewFile();
System.out.println(file1);
System.out.println("Hello Buddy what are upto.....##########################");
OutputStreamWriter os = new OutputStreamWriter(
new FileOutputStream(file1));
bw = new BufferedWriter(os);
Process process = Runtime.getRuntime().exec(
"logcat -v threadtime -s ServiceMode");
int length = process.toString().length();
System.out.println("Length" + length);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuffer output1 = new StringBuffer();
while ((line = reader.readLine()) != null) {
bw.write(line);
bw.newLine();
}
} catch (IOException e) {
}
here is Logcat
D/action: 0
D/ACTION:: BOTH
D/Log3GState:: Accessing file
D/Create file: /data/user/0/com.services.snifspoof.snifspoof/C_packetCapture
D/Log3GState:: Write executable file
D/EGL_emulation: eglMakeCurrent: 0x9ef850c0: ver 2 0 (tinfo 0x9ef831f0)
D/EGL_emulation: eglMakeCurrent: 0x9ef850c0: ver 2 0 (tinfo 0x9ef831f0)
D/CLOSING: BOTH
I/System.out: *********#############
I/System.out: *********############# File Created :- /storage/emulated/0/Sniffing/dump1.txt
I/System.out: Length34
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: com.services.snifspoof.snifspoof, PID: 2389
java.lang.NullPointerException: Attempt to invoke a virtual method on a null object reference
at com.services.snifspoof.snifspoof.MainActivity$3$1.run(MainActivity.java:167)
at java.lang.Thread.run(Thread.java:761)