this is my actual class I am writing test class below.
public class ReadFile {
private Scanner rx, tx;
public void openFile() {
try {
rx = new Scanner(new File("/sys/class/net/eth0/statistics/rx_bytes"));
tx = new Scanner(new File("/sys/class/net/eth0/statistics/tx_bytes"));
} catch (Exception e) {
e.printStackTrace();
}
}
public String readRxFile() {
String rxData = "";
while (rx.hasNext()) {
rxData = rx.next();
}
return rxData;
}
public String readTxFile() {
String txData = "";
while (tx.hasNext()) {
txData = tx.next();
}
return txData;
}
public void closeFile() {
rx.close();
tx.close();
}
}
this is test class. to test the read data.
public class Testreadrxfile extends TestCase {
public Testreadrxfile() {
super();
}
protected void setUp() throws Exception {
try {
super.setUp();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ReadFile rf;
public void testappdata() {
String str1 = rf.readRxFile();
Assert.assertEquals("14081",str1 );
}
}
this is the error I am getting.
java.lang.NullPointerException
atcom.android.deviceintelligence1. test.Testreadrxfile.testappdata(Testreadrxfile.java:26)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
this is not activity or service test to use getactivity() or getservice() so what I should do to get out of this error . thanks for help in advance.
see your code..
rfis not initialised..