Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:21+00:00 2026-05-26T01:41:21+00:00

This is a snippet from my Robolectric enabled JUnit test class : @Before public

  • 0

This is a snippet from my Robolectric enabled JUnit test class :

@Before
    public void setUp() throws Exception
    {
        mActivity = new LanguageSelection();
        mActivity.onCreate(null);

        speakEnglishButton = (Button) mActivity.findViewById(com.jameselsey.apps.androidsam.R.id.speakEnglishButton);
        speakSpanishButton = (Button) mActivity.findViewById(com.jameselsey.apps.androidsam.R.id.speakSpanishButton);
        speakFrenchButton = (Button) mActivity.findViewById(com.jameselsey.apps.androidsam.R.id.speakFrenchButton);
        speakGermanButton = (Button) mActivity.findViewById(com.jameselsey.apps.androidsam.R.id.speakGermanButton);
        speakItalianButton = (Button) mActivity.findViewById(com.jameselsey.apps.androidsam.R.id.speakItalianButton);
    }

    @Test
    public void testButtonsVisible()
    {
        assertThat(speakEnglishButton.getVisibility(), equalTo(View.VISIBLE));
        assertThat(speakSpanishButton.getVisibility(), equalTo(View.VISIBLE));
        assertThat(speakFrenchButton.getVisibility(), equalTo(View.VISIBLE));
        assertThat(speakGermanButton.getVisibility(), equalTo(View.VISIBLE));
        assertThat(speakItalianButton.getVisibility(), equalTo(View.VISIBLE));
    }

The line mActivity.onCreate(null) throws the following exception when my tests are run :

java.lang.RuntimeException: error inflating layout/languageselection
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:101)
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:79)
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:83)
    at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:33)
    at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.xtremelabs.robolectric.ShadowWrangler.methodInvoked(ShadowWrangler.java:78)
    at com.xtremelabs.robolectric.RobolectricInternals.methodInvoked(RobolectricInternals.java:50)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at com.xtremelabs.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at com.xtremelabs.robolectric.ShadowWrangler.methodInvoked(ShadowWrangler.java:78)
    at com.xtremelabs.robolectric.RobolectricInternals.methodInvoked(RobolectricInternals.java:50)
    at android.app.Activity.setContentView(Activity.java)
    at com.jameselsey.apps.androidsam.LanguageSelection.onCreate(LanguageSelection.java:28)
    at com.jameselsey.apps.androidsam.LanguageSelectionTest.setUp(LanguageSelectionTest.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at com.xtremelabs.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:164)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:60)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.xtremelabs.robolectric.res.ViewLoader$ViewNode.constructView(ViewLoader.java:161)
    at com.xtremelabs.robolectric.res.ViewLoader$ViewNode.create(ViewLoader.java:144)
    at com.xtremelabs.robolectric.res.ViewLoader$ViewNode.inflate(ViewLoader.java:126)
    at com.xtremelabs.robolectric.res.ViewLoader$ViewNode.inflate(ViewLoader.java:129)
    at com.xtremelabs.robolectric.res.ViewLoader$ViewNode.inflate(ViewLoader.java:129)
    at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:99)
    ... 51 more
Caused by: java.lang.UnsupportedOperationException
    at com.xtremelabs.robolectric.util.TestAttributeSet.getAttributeUnsignedIntValue(TestAttributeSet.java:69)
    at com.admob.android.ads.AdView.<init>(AdView.java:366)
    at com.admob.android.ads.AdView.<init>(AdView.java:308)
    at com.admob.android.ads.AdView.<init>(AdView.java:295)
    ... 61 more

If I comment out the following view from my languageselection.xml layout file, it works perfectly fine :

<com.admob.android.ads.AdView
                android:id="@+id/ad"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="bottom"
                androidsam:backgroundColor="#000000"
                androidsam:primaryTextColor="#FFFFFF"
                androidsam:secondaryTextColor="#CCCCCC"/>

Question : What is a good work around for this? I don’t want to have to disable/enable ads purely for testing purposes. I’m not testing the ads, but I don’t want to have to remove them for testing of other elements such as buttons.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:41:22+00:00Added an answer on May 26, 2026 at 1:41 am

    I would recommend moving the code snippet where you look up the admob ads from the onCreate method and place them into the onResume method which gets called straight after onCreate.

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView) this.findViewById(R.id.adView);
    
    // Request an advertisement
    AdRequest request = new AdRequest();
    request.setTesting(true); //This is used for testing on emulator. Does not affect production
    adView.loadAd(request);
    

    I’m not sure why it’s blowing up but it works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This snippet is from forms.py: class TestForm(forms.Form): Specialist = forms.ModelChoiceField(label = 'Test', queryset =
This is a snippet from a prototype class i am putting together. The scoping
I have this snippet of code from a class created by Erica Sadun, that
Can someone explain what the dict class is used for? This snippet is from
How would I modify this snippet from the tutorial Ext.get(document.body).update('<div id=test></div>'); new Ext.Panel({ renderTo:
This snippet from official website works as expected: $treeObject = Doctrine::getTable('Category')->getTree(); $rootColumnName = $treeObject->getAttribute('rootColumnName');
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
What's wrong with this snippet of code? import numpy as np from scipy import
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.