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 8736151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:14:23+00:00 2026-06-13T10:14:23+00:00

I have trouble running some test cases, which broke after I upgraded the api

  • 0

I have trouble running some test cases, which broke after I upgraded the api to 4.1 (not sure if it is related, but the error doesn’t seem to suggest so)

java.lang.RuntimeException: java.lang.InstantiationException
at com.xtremelabs.robolectric.bytecode.RobolectricInternals.newInstanceOf(RobolectricInternals.java:32)
at com.xtremelabs.robolectric.Robolectric.newInstanceOf(Robolectric.java:130)
at com.xtremelabs.robolectric.shadows.ShadowWebView.<init>(ShadowWebView.java:21)
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 java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.xtremelabs.robolectric.bytecode.ShadowWrangler.shadowFor(ShadowWrangler.java:163)
at com.xtremelabs.robolectric.bytecode.ShadowWrangler$InvocationPlan.prepare(ShadowWrangler.java:311)
at com.xtremelabs.robolectric.bytecode.ShadowWrangler.methodInvoked(ShadowWrangler.java:81)
at com.xtremelabs.robolectric.bytecode.RobolectricInternals.methodInvoked(RobolectricInternals.java:111)
at android.view.View.<init>(View.java)
at android.view.ViewGroup.<init>(ViewGroup.java)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java)
at android.webkit.WebView.<init>(WebView.java)

in the given class of ShadowWebView,
There is a line

private WebSettings webSettings = Robolectric.newInstanceOf(WebSettings.class);

The above line leads to

  Robolectric.java

which then leads to RobolectricInternals.java and executes the following method

   public static <T> T newInstanceOf(Class<T> clazz)

the method has the following source code:

public static <T> T newInstanceOf(Class<T> clazz) {
    try {
        Constructor<T> defaultConstructor = clazz.getDeclaredConstructor();
        defaultConstructor.setAccessible(true);
        return defaultConstructor.newInstance();
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

the exception thrown (u see in the error log above) is because of this line

    defaultConstructor.newInstance();

i am not sure what is causing this and how to fix this
only observation i made was the WebSettings.java from android used to be a non-abstract class, but now it is an abstract class, i thought this was the culprit, but then when i switched to older api such as level 12, (for which websettings.java is not declared abstract), i still have the same error

  • 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-06-13T10:14:24+00:00Added an answer on June 13, 2026 at 10:14 am

    You are correct that Android’s WebSettings became an abstract class in API 16.

    At API 16, Robolectric could no longer create an instance of WebSettings via:

    private WebSettings webSettings = Robolectric.newInstanceOf(WebSettings.class);
    

    because WebSettings is abstract and cannot be instantiated even by reflection.

    Because WebSettings became abstract, Robolectric has to somehow offer a concrete instantiation of WebSettings. So I created the android.webkit.TestWebSettings class, and made Robolectric return an instance of that in ShadowWebView#getSettings.

    As to your specific problem – that you switched to API 12 but still cannot instantiate WebSettings. This is likely to be the case even if you change your project to a lower API level, because Robolectric itself is still built against the android-16.jar. If you change Robolectric itself to build against android-12.jar, you will get an instance of WebSettings – but without a shadow implementation because ShadowWebSettings has been removed from the current version of Robolectric.

    The easiest workaround for your problem would probably be to update your project to API 16, and then instantiate a TestWebSettings object directly in your test case. So instead of:

    private WebSettings webSettings = Robolectric.newInstanceOf(WebSettings.class);
    

    you would write:

    private WebSettings webSettings = new TestWebSettings();
    

    You can find the TestWebSettings class in the android.webkit package that is part of the Robolectric source:

    import android.webkit.TestWebSettings;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm exploring package building on Windows 7 but have been running into trouble after
Having some trouble refreshing the image, i have a script running in the background
I am running into an error I am having trouble figuring out. I have
I have trouble where, for some reason, SVN would only merge the newly generated
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish
I'm getting my head around Modernizr polyfill loading today and running into some trouble.
I have some trouble with a spreadsheet: as said in the title, I put
I have some trouble with python. I am trying to get output from a
I am trying to do a unit test on some c++ code but am
I'm running into some trouble running python/mysqldb on my raspberry pi. This is a

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.