我目前正在对来自android website的示例 TabLayout 进行单元测试。当像这样对它进行单元测试时,我得到一个 NullPointerException:
public class MainActivityUnitTest extends ActivityUnitTestCase<MainActivity>{
public MainActivityUnitTest(){
super(MainActivity.class);
}
@MediumTest
public void testStartActivity(){
setActivity(startActivity(new Intent(Intent.ACTION_MAIN), null, null));
}
}
这是我得到的例外:
java.lang.NullPointerException
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
at android.widget.TabHost.setCurrentTab(TabHost.java:326)
at android.widget.TabHost.addTab(TabHost.java:216)
at com.foo.android.MainActivity.onCreate(MainActivity.java:55)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:159)
at com.foo.android.test.MainActivityUnitTest.testStartActivity(MainActivityUnitTest.java:17)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
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)
我试图在没有运气的情况下搜索网络。我希望有人以前解决过这样的问题。我在这里做错了什么?非常感谢您的帮助。