Android의 RelativeLayout에 대한 단위 테스트를 작성하려고합니다. 현재 내 testcode 설정은 다음과 같습니다Android의 RelativeLayout 단위 테스트 설정
public class SampleRelativeLayoutTest extends AndroidTestCase {
private ViewGroup testView;
private ImageView icon;
private TextView title;
@Override
protected void setUp() throws Exception {
super.setUp();
// inflate the layout
final Context context = getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
testView = (ViewGroup) inflater.inflate(R.layout.sample_layout,
null);
// manually measure and layout
testView.measure(500, 500);
testView.layout(0, 0, 500, 500);
// init variables
icon = (ImageView) testView.findViewById(R.id.icon);
title = (TextView) testView.findViewById(R.id.title);
}
그러나, 나는 다음과 같은 스택 추적 제가 제대로 테스트 실행을 만들기 위해() 코드 내 설정에서 변경해야합니까
java.lang.NullPointerException
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:427)
at android.view.View.measure(View.java:7964)
at com.dqminh.test.view.SampleRelativeLayoutTest.setUp(SampleRelativeLayoutTest.java:33)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
와 NullPointerException이 발생?
이것은 내게 매력적이었습니다. http://stackoverflow.com/a/6086510/1293704 – Primoz990