Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when creating visible Activities in @BeforeClass #1232

Closed
entropitor opened this issue Aug 15, 2014 · 9 comments
Closed

NPE when creating visible Activities in @BeforeClass #1232

entropitor opened this issue Aug 15, 2014 · 9 comments

Comments

@entropitor
Copy link

activity = Robolectric.buildActivity(LoginActivity.class).create().visible().get();

gives an error when in a JUnit's @BeforeClass (see bottom for stacktrace);

while activity = Robolectric.buildActivity(LoginActivity.class).get();
(notice how create() and visible() are gone) doesn't throw an error.

java.lang.NullPointerException
    at android.content.ComponentName.__constructor__(ComponentName.java:75)
    at android.content.ComponentName.<init>(ComponentName.java:74)
    at org.robolectric.shadows.ShadowIntent.__constructor__(ShadowIntent.java:55)
    at android.content.Intent.<init>(Intent.java:3661)
    at org.robolectric.util.ComponentController.getIntent(ComponentController.java:67)
    at org.robolectric.util.ActivityController.getIntent(ActivityController.java:29)
    at org.robolectric.util.ActivityController.attach(ActivityController.java:51)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:112)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265)
    at org.robolectric.util.ActivityController.create(ActivityController.java:110)
    at org.robolectric.util.ActivityController.create(ActivityController.java:120)
    at packagename.LoginCallbackTest.setupClass(LoginCallbackTest.java:36)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.robolectric.RobolectricTestRunner.invokeBeforeClass(RobolectricTestRunner.java:282)
    at org.robolectric.RobolectricTestRunner.access$500(RobolectricTestRunner.java:61)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:55)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
@geldka
Copy link

geldka commented Oct 29, 2014

I have the same issue. Did you resolve this problem?

@entropitor
Copy link
Author

I think I just moved it into a @Before method.

@venkatraman7
Copy link

I have the issue in which ActivityController object returns null. I am using below lines to create Activity @before method
final ActivityController controller = Robolectric.buildActivity(FirstActivity.class);
firstActivity = controller.create().start().resume().visible().get();
firstActivity.getActionBar().hide();

I am getting NPE and all my tests getting failed because of this which are passed before. I am uing Robolectric 2.3

@jaredsburrows
Copy link
Contributor

Why use @BeforeClass vs @Before? What is the status of this? Can you close this now?

@erd erd added the 2.3 label May 20, 2015
@jaredsburrows
Copy link
Contributor

@erd This is what I am talking about. This issue is really old and there is no replies on how to duplicate or if the issue still exists. Can we just close this? This should be put in @Before.

@erd erd closed this as completed May 30, 2015
@dsharew
Copy link

dsharew commented Nov 25, 2015

I am having this issue.

my code:

 @Before
    public void setup() {

        activity = Robolectric.buildActivity(Home.class).create().get();

    }

@jongerrish
Copy link
Contributor

Stack trace?

On 24 November 2015 at 23:05, yamo21 notifications@github.com wrote:

I am having this issue.

my code:

` @before https://github.com/Before
public void setup() {

activity = Robolectric.buildActivity(Home.class).create().get();

}`


Reply to this email directly or view it on GitHub
#1232 (comment)
.

@dsharew
Copy link

dsharew commented Nov 26, 2015

java.lang.NullPointerException
    at org.robolectric.res.ResBundle$Value.compareTo(ResBundle.java:189)
    at org.robolectric.res.ResBundle$Value.compareTo(ResBundle.java:166)
    at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:290)
    at java.util.ComparableTimSort.sort(ComparableTimSort.java:157)
    at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
    at java.util.Arrays.sort(Arrays.java:472)
    at java.util.Collections.sort(Collections.java:155)
    at org.robolectric.res.ResBundle.put(ResBundle.java:32)
    at org.robolectric.res.ResBunch.put(ResBunch.java:12)
    at org.robolectric.res.StyleResourceLoader.processNode(StyleResourceLoader.java:35)
    at org.robolectric.res.XpathResourceXmlLoader.processResourceXml(XpathResourceXmlLoader.java:22)
    at org.robolectric.res.XmlLoader.processResourceXml(XmlLoader.java:46)
    at org.robolectric.res.DocumentLoader.loadResourceXmlFile(DocumentLoader.java:47)
    at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:40)
    at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:30)
    at org.robolectric.res.PackageResourceLoader.loadEverything(PackageResourceLoader.java:32)
    at org.robolectric.res.PackageResourceLoader.doInitialize(PackageResourceLoader.java:19)
    at org.robolectric.res.XResourceLoader.initialize(XResourceLoader.java:29)
    at org.robolectric.res.OverlayResourceLoader.doInitialize(OverlayResourceLoader.java:22)
    at org.robolectric.res.XResourceLoader.initialize(XResourceLoader.java:29)
    at org.robolectric.res.XResourceLoader.getValue(XResourceLoader.java:52)
    at org.robolectric.res.OverlayResourceLoader.getValue(OverlayResourceLoader.java:51)
    at org.robolectric.res.RoutingResourceLoader.getValue(RoutingResourceLoader.java:31)
    at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:356)
    at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:352)
    at org.robolectric.shadows.ShadowAssetManager.getResourceText(ShadowAssetManager.java:70)
    at android.content.res.AssetManager.getResourceText(AssetManager.java)
    at android.content.res.Resources.getText(Resources.java:270)
    at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:358)
    at android.content.res.Resources.getText(Resources.java)
    at android.content.res.Resources.getString(Resources.java:360)
    at org.robolectric.shadows.ShadowContext.getString(ShadowContext.java:33)
    at org.robolectric.shadows.ShadowContextWrapper.getString(ShadowContextWrapper.java:81)
    at android.content.Context.getString(Context.java)
    at org.robolectric.util.ActivityController.getActivityTitle(ActivityController.java:108)
    at org.robolectric.util.ActivityController.attach(ActivityController.java:49)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:121)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
    at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
    at org.robolectric.util.ActivityController.create(ActivityController.java:118)
    at org.robolectric.util.ActivityController.create(ActivityController.java:129)
    at com.apposit.vms.mobile.test.unit.activity.LoginTest.setup(LoginTest.java:42)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

@nguyenmike
Copy link

I have the same issue with yamo21 when build the test by "gradlew test".
The tests work fine when run on Android studio.
Please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants