问题描述
应用程序支持 minSdk = 14
并动作条
每活动
。
应用程序工作正常,因为很长一段时间,并显示动作条
每活动
。现在我写的Android 的JUnit
测试用例
,但它给了 NullPointException
在线
底线是 getActionBar()
在测试用例工程设备,但回报率空
。如果删除该行,然后测试用例都很好。
下面是如何活动的样子。
JUnits
是简单的Android的JUnit测试案例,没有任何框架。
和在运行测试用例终于在这里是个例外。
显示java.lang.NullPointerException
在com.example.name.OrderActivity.onCreate(OrderActivity.java:176)
在android.app.Activity.performCreate(Activity.java:5231)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
在android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)
在com.example.name.test.OrderActivityTest.setUp(OrderActivityTest.java:23)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
在android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1701)
176
行是 getActionBar()setDisplayHomeAsUpEnabled(真);
getActionBar()可能返回null这里。标题必须是可见的,请确保你没有这样的事情有:
安卓主题=@安卓风格/ Theme.Black.NoTitleBar
这会导致getActionBar(错误)被空。
Application supports minSdk=14
and have ActionBar
on every Activity
.
Application works fine since a long time and shows ActionBar
on every Activity
. Now I am writing Android JUnit
Testcases
but it gives NullPointException
on line
The bottom line is getActionBar()
works on devices but returns null
during test cases. If I remove the line then testcases are fine.
Here's how activity looks like.
JUnits
are simple Android JUnit Testcases without any framework.
And finally here's the exception while running test case.
java.lang.NullPointerException
at com.example.name.OrderActivity.onCreate(OrderActivity.java:176)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)
at com.example.name.test.OrderActivityTest.setUp(OrderActivityTest.java:23)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Line 176 is getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar() is probably returning null here. The title needs to be visible, make sure you don't have things like this there:
android:theme="@android:style/Theme.Black.NoTitleBar
This would cause an error in getActionBar() being null.
这篇关于getActionBar()正常工作的设备/模拟器但在测试用例返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!