I'm testing two activities: the first one completes its tests and finishes, but the first test in the second one crashes with the following error:
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.NullPointerException''. Check device logcat for details
I figured the line activity = getActivity();
in the test class gives a null and thus crashes the test. Here's the relevant part of the test class. Why does this happen, and how do I fix it?
public ResultActivityTest() {
super(ResultActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
activity = getActivity();
displayoperands = (TextView) activity.findViewById(R.id.result_textview);
resultdisplay = (TextView) activity.findViewById(R.id.textView2);
canvas = (SurfaceView) activity.findViewById(R.id.surfaceview);
layoutRoot = (RelativeLayout) activity.findViewById(R.id.rellay);
back = (Button) activity.findViewById(R.id.back_button);
activity.setImag1(2.0);
activity.setImag2(2.0);
activity.setReal1(2.0);
activity.setReal2(2.0);
activity.setOperation("A");
}