1

I am getting the above exception when trying to run my code (below) on a Nexus 5 emulator (API 24 / Google APIs)...

E/ACRA: ACRA caught a RuntimeException for com.example
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.SplashActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
            at android.app.ActivityThread.-wrap12(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:154)
            at android.app.ActivityThread.main(ActivityThread.java:6077)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
         Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
         Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
         Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.newInstance0(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
            at android.view.LayoutInflater.createView(LayoutInflater.java:645)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
            at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
            at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:414)
            at com.android.internal.app.AlertController.installContent(AlertController.java:236)
            at android.app.AlertDialog.onCreate(AlertDialog.java:423)
            at android.app.Dialog.dispatchOnCreate(Dialog.java:389)
            at android.app.Dialog.show(Dialog.java:293)
            at com.example.SplashActivity.checkPlayServices(SplashActivity.java:195)
            at com.example.SplashActivity.onCreate(SplashActivity.java:74)
            at android.app.Activity.performCreate(Activity.java:6664)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
            at android.app.ActivityThread.-wrap12(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:154)
            at android.app.ActivityThread.main(ActivityThread.java:6077)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
         Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
            at android.content.res.TypedArray.getColorStateList(TypedArray.java:528)
            at android.widget.TextView.<init>(TextView.java:783)
            at android.widget.TextView.<init>(TextView.java:704)
            at android.widget.TextView.<init>(TextView.java:700)
E/ACRA:     at com.android.internal.widget.DialogTitle.<init>(DialogTitle.java:41)
                ... 34 more

I seen answers to similar questions that suggest passing SplashActivity.this to the Dialog constructor rather than passing getApplicationContext() - but I am already passing an instance of the activity.

Any ideas what could be wrong?

My code!...

private boolean checkPlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if (result != ConnectionResult.SUCCESS) {
    if (googleAPI.isUserResolvableError(result)) {
        Dialog dialog = googleAPI.getErrorDialog(this, result, PLAY_SERVICES_RESOLUTION_REQUEST);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            SplashActivity.this.finish();
        }
        });
        dialog.show();
    }
    return false;
    }
    return true;
}
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253

2 Answers2

0

The error way down below tells you

java.lang.UnsupportedOperationException: 
   Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}

and this seems to happen while a ColorStateList is tried to be evaluated on your target device. So I'd check the color definitions if there is any XML attribute that has a discrepancy with the minSdk of your application. In general, executing Lint might also directly point you to such an error, as this is very good at finding these things (use ./gradlew lint on command line).

Thomas Keller
  • 5,933
  • 6
  • 48
  • 80
  • Thanks for your help. Can you give me a bit guidance on how to check the colour definitions and where/how to use `./gradlew lint` as I'm not familiar with either of those. (NB - The minSdkVersion of my app is 15.) – ban-geoengineering Sep 26 '16 at 20:49
  • Open up the "Terminal" window in Android Studio in the bottom drawer. On Windows, you need to type in and execute `gradlew.bat lint`, on macOS and Linux it is the said `./gradlew lint` command. – Thomas Keller Sep 26 '16 at 20:52
  • I executed `gradlew.bat lint` in Terminal, and it came up with 3 errors relating to the twitter4j dependency, so I have removed that from my project, but I'm still getting the same exception. However, I have noticed this warning: `W/GooglePlayServicesUtil: Google Play services out of date. Requires 9683000 but found 9452480` which might be the underlying problem? – ban-geoengineering Sep 26 '16 at 22:07
  • There's a discussion of it here: https://code.google.com/p/android/issues/detail?id=212879 . And a suggested solution here: http://stackoverflow.com/a/39706752/1617737 - but it didn't work for me... :-/ – ban-geoengineering Sep 26 '16 at 22:24
  • Actually, I think the problem you're having seems to be more Support-library related. See if this fixes your issue: http://stackoverflow.com/questions/30595187/android-xml-runtimeexception-failed-to-resolve-attribute-at-index-6 – Thomas Keller Sep 26 '16 at 22:56
  • Thanks, but nothing there seems to help. My theme is already using AppCompat, and I've changed everything (emulator, compileSdkVersion, buildToolsVersion, targetSdkVersion and support libraries) down from API 24 to API 23, but I'm still getting the same problem. – ban-geoengineering Sep 27 '16 at 09:24
0

I found the solution, thanks to Thomas Keller's comments on his answer.

Basically, I had used my own Dialog styles in my v21\style.xml file:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:alertDialogTheme">@style/MyAlertDialog</item>
    <item name="alertDialogTheme">@style/MyAlertDialog</item>
</style>

<style name="MyAlertDialog" parent="Theme.AppCompat.Dialog.Alert">
    <item name="colorAccent">?attr/colorAccent</item>
</style>

The Google API dialog was trying to use this style, so removing it from my xml has fixed the issue.

However, I would still like to use MyAlertDialog (for its colorAccent value), so does anyone know what colors I must add to it in order to appease the Google API dialog (and any other Google/system dialogs)?

Community
  • 1
  • 1
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253