2

So, recently I had to move my project from where it was due to the Error: File path too long on windows, keep below 240 characters. After moving, and solving other errors when I run my project, the app crashes with android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer. Unfortunately, I cannot post the logcat message as it is too big to post, so I will just put some Caused by messages here. Apart from the inflate exception the other two exceptions are: Caused by: java.lang.reflect.InvocationTargetException and Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13. All of the exceptions and the error itself refers to a class' setContentView(R.layout.activity_automatic_floor_plan_loader);. In this layout file I am using AppTheme.AppBarOverlay. I am quite sure everything relates to this apptheme, but I do not know what to change and how to. I have gone through many Stackoverflow questions, but none of them seems to answer or solve the error I am getting. Here is my Style.xml file: Style.xml

And here is my class' activity in the Android-Manifest.xml file: AndroidManifest.xml

And here is my activity.xml (activity_automatic_floor_plan_loader): activity.xml

And here is my build.gradle(app) file: Build.gradle How to solve this error? Many thanks.

Community
  • 1
  • 1
Neel0507
  • 1,094
  • 2
  • 11
  • 18
  • 1
    Possible duplicate of [(Activity+preferencefragment) Error inflating class com.android.internal.widget.ActionBarContainer](http://stackoverflow.com/questions/34567982/activitypreferencefragment-error-inflating-class-com-android-internal-widget) – Artjom B. Jan 03 '16 at 13:47
  • ThemeOverlays only supply some attributes. Thats why you use them on widgets where they override these attributes of parent activity theme. Your activity must have a regular Theme in your case `@style/AppTheme`. – Eugen Pechanec Jan 03 '16 at 14:07
  • In addition what you probably wanted is `@style/AppTheme.AppBarOverlay` and similarly for `actionBarPopupTheme`. – Eugen Pechanec Jan 03 '16 at 14:14
  • I posted this question one month ago, and I am trying to help others as I already know the solution. So how come this question which was posted before any other related questions is duplicate? and also I have edited my answer for my own question to help others and doesn't contain any link to other questions any more. – Neel0507 Jan 03 '16 at 14:16
  • Ah, I see. In that case either mark an answer or delete the question altogether so the feed is clean. Thank you. – Eugen Pechanec Jan 03 '16 at 14:21
  • I marked my own answer as the solution worked for me and as I had no choice. – Neel0507 Jan 03 '16 at 15:04

2 Answers2

1

Here is how I solved this error:

  1. In the styles.xml file, in the first "AppTheme" style I had to put Base infront of Theme.AppCompat. So it would be "Base.Theme.AppCompat.Light.DarkActionBar".

  2. Then I used android:theme="@style/AppTheme" in my parent activity in androidmanifest.xml.

  3. In the androidmanifest file in the child activity, I had to put android:parentActivityName=".parentActivity" and I removed android:theme="@style/AppTheme.AppBarOverlay" from the child activity and put it in the activity.xml (child activity) file as below.

  4. In the activity.xml file in the LinearLayout tag, I had to put android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar". It is the parent of the "@style/AppTheme.AppBarOverlay".

This 4 step process worked for me, and if you are getting this error, just follow these steps and it should work for you as well.

Edit: It turned out that the solution was very simple. To have an action bar in any of your activities, you just need to extend AppCompatActivity. Only my main activity was extending AppCompatActivity and not other activities. The above approach for getting an action bar is quite vague and I knew it, however, it worked initially, but now I have the correct and straight forward solution and if you are getting such error then just check that whether you are extending AppCompatActivity in your class or not.

Neel0507
  • 1,094
  • 2
  • 11
  • 18
0

You set a ThemeOverlay as your Activity theme. ThemeOverlay only specifies certain attributes so when used on a widget it overlays these attributes over the original activity or parent widget theme. Your Activity must use a full fledged Theme such as your AppTheme.

This is probably what you were looking for:

values/styles.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="actionBarTheme">@style/AppTheme.AppBarOverlay</item>
    <item name="actionBarPopupTheme">@style/AppTheme.PopupOverlay</item>
</style>

AndroidManifest.xml

<activity
    android:theme="@style/AppTheme">
</activity>
Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124