5

When creating a new project in Android Studio while using the latest updates and after adding compile com.android.support:appcompat-v7:22.1.0 to the dependencies still have this issue (which is solved if I'm using API 21):

Exception Details java.lang.NoSuchFieldError: View_theme   at android.support.v7.internal.widget.ViewUtils.themifyContext(ViewUtils.java:124)   at android.support.v7.widget.Toolbar.(Toolbar.java:198)   at android.support.v7.widget.Toolbar.(Toolbar.java:192)   at java.lang.reflect.Constructor.newInstance(Constructor.java:422)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)   at android.view.LayoutInflater.inflate(LayoutInflater.java:504)   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)   at com.android.layoutlib.bridge.bars.BridgeActionBar.(BridgeActionBar.java:84)   at com.android.layoutlib.bridge.bars.AppCompatActionBar.(AppCompatActionBar.java:56)

When i opened projects that was originally created with eclipse the rendering for API 22 worked great on Android Studio .

Can someone please explain this ?

Another issue that i encountered is that when upgrading the SDK it adds the Android M API and it called API 22 just as Android 5.1.1 which can also cause rendering issues . The solution is just to switch back to API 22 5.1.1 Hope it helps .

liorlis
  • 216
  • 3
  • 14

2 Answers2

1

Update : Doing a Build>Clean Project or a gradle Sync Project will solve the problem.

Old answer : According to 22.1 changelog (source) :

Lollipop added the ability to overwrite the theme at a view by view level by using the android:theme XML attribute - incredibly useful for things such as dark action bars on light activities. Now, AppCompat allows you to use android:theme for Toolbars (deprecating the app:theme used previously) and, even better, brings android:theme support to all views on API 11+ devices.

So i guess if you change app:theme to android:theme it will work.

Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
1

In my case, solution was as simple as

  1. Add @style to the parent theme
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
  1. remove android.support.v7.widget. from Toolbar

  2. move from app:theme to android:theme

<Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Eloi Navarro
  • 1,435
  • 1
  • 14
  • 26
  • I've the same issue and also I'm new to android studio. Please could you tell in which file have you applied the above changes? Thanks. – Vicent Jul 03 '15 at 08:59
  • The first one in styles.xml the rest in every layout you use a Toolbar element – Eloi Navarro Jul 03 '15 at 10:00