java.lang.NoSuchFieldError: android.support.v7.appcompat

谁说我不能喝 提交于 2019-12-04 13:53:44

问题


I updated my support library from r20 to r21, now when I run my app I get this error in super.onCreate of my main activity :

java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.Theme_windowActionBar
    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:145)
    at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:139)
    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
    at (packageName).Main.onCreate(Main.java:64)
    at android.app.Activity.performCreate(Activity.java)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
    at android.app.ActivityThread.access$700(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
    at android.os.Handler.dispatchMessage(Handler.java)
    at android.os.Looper.loop(Looper.java)
    at android.app.ActivityThread.main(ActivityThread.java)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
    at dalvik.system.NativeStart.main(Native Method)

my theme.xml :

<style name="AppBaseTheme" parent="Theme.AppCompat">
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item> ... </item>
</style>

in manifest :

android:theme="@style/AppTheme"

what is the problem ?

thanks


回答1:


It happened same to me when I update SDK. If you have version 21 of library "Android Support Library" this bug occurs. I don't know what is the reason but last release make this bug.

You can solve it by downloading previous version of "Android Support Library" (r20) from here: https://dl-ssl.google.com/android/repository/support_r20.zip, and using it in your project.

You are welcome!




回答2:


I have compared support_v7_appcompat (version 20) with support_v7_appcompat (version 21). In res/values/attrs.xml (version 21), windowActionBar attributes are not in <declare-styleable name="Theme">




回答3:


if you use intellij => you have to add in /project strutures/modules/ => YOURSDK\extras\android\support\v7\appcompat and add after in your project like that you have always the last support



来源:https://stackoverflow.com/questions/26655183/java-lang-nosuchfielderror-android-support-v7-appcompat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!