獲取Nullpointer異常我目前正在單元測試從android website的示例TabLayout。這樣的單元測試時,我得到一個NullPointerException異常:當UnitTesting Android TabActivity
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)
我試過,沒有運氣搜索網。我希望以前有人解決過這樣的問題。我在這裏做錯了什麼?非常感謝您的幫助。
難道歐盟解決這個問題? – kaneda 2011-09-14 00:21:30
您能否正常工作? – WindsurferOak 2011-10-25 21:17:43
我有同樣的問題。 – isHwang 2012-03-26 02:12:22