4

I have implemented Android application for reading books. My application has two modes - day and night.

For day mode I am using theme, which has the parent set to @style/Theme.AppCompat.Light.NoActionBar. For the night mode the parent is @style/Theme.AppCompat.NoActionBar.

In the first mode (day) everything works fine. But there is a problem when user change mode to night. I have a problem with Spinner, which is placed in my fragment. Immediately after changing mode to night I see the following exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.company.media/cz.comapy.reader.activity.reader.ReadingActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5111)
     at android.app.ActivityThread.access$1100(ActivityThread.java:198)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:145)
     at android.app.ActivityThread.main(ActivityThread.java:6837)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
  Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
     at android.view.LayoutInflater.createView(LayoutInflater.java:640)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:366)

I found out that there is a Spinner in my layout on line 19. I am targeting SDK version 22. All of my activities extend from AppCompatActivity and all of my dialogs extend from AppCompatDialogFragment. I also tried to change Spinner to AppCompatSpinner, but it has no effect.

And it is very weird, that this happened to me only on device Samsung Galaxy S6 with Android 5.1.1.

I tested it on some other devices, like Nexus 5, Samsung Galaxy S4, Motorola Xoom, Xperia Z2 tablet and it works absolutely fine.

Does anybody have an idea, what could be wrong?

UPDATE

On line 19 in my xml file is following:

<android.support.v7.widget.AppCompatSpinner [this is line 19]
        android:id="@+id/spinner_display_settings_motif"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/display_setting_motif_types"/>

I also tried to use classic Spinner, but it is same.

PetrS
  • 1,110
  • 14
  • 38
  • 1
    Ran into many problems with the default (dark) theme myself, have you tried android:theme="@style/ThemeOverlay.AppCompat.Dark" ? – Markus Rubey Dec 17 '15 at 15:44
  • @MarkusRubey I am using Toolbar, so I suppose that I cannot use this theme. – PetrS Dec 18 '15 at 22:15
  • If your activity extends specifically ActionBarActivity and the theme is for activity's without an action bar then it could cause a crash. Often times if there is anything missing or missing because of a theme change the crash can occur. AppCompatActivity is deprecated so if the the theme maybe only supports new one. – Eae Dec 21 '15 at 17:31
  • What is on line 19 of XML? – Eae Dec 21 '15 at 17:37
  • @Sepoto See my updated question, please. My activity extends from `AppCompatActivity` and there is no `ActionBar`, because I am using `Toolbar`. – PetrS Dec 22 '15 at 08:44
  • There is an example how to apply v7 compat theme http://stackoverflow.com/questions/31499657/spinner-theme-is-dark-in-android. Im not sure i have a direct solution – Eae Dec 22 '15 at 12:12
  • ive also had this type of exception happen if the constructor of the activity or spinner if the control has a class needs to have the attributeset param added to it – Eae Dec 23 '15 at 12:34

1 Answers1

1

Try to check, if you don't have in your style / theme:

<item name="android:src">something</item>

This can cause this kind of problems.

Warlock
  • 2,481
  • 4
  • 31
  • 45