java.lang.NoSuchFieldError android/support/v7/AppCompat/

2022-09-04 07:46:08

今天启动日食后,我运行的任何项目都会返回以下错误:

08-06 08:01:23.770: E/AndroidRuntime(5406): FATAL EXCEPTION: main
08-06 08:01:23.770: E/AndroidRuntime(5406): Process: be.thomasmore.powerfactory, PID: 5406
08-06 08:01:23.770: E/AndroidRuntime(5406): java.lang.NoSuchFieldError: No static field abc_screen_toolbar of type I in class Landroid/support/v7/appcompat/R$layout; or its superclasses (declaration of 'android.support.v7.appcompat.R$layout' appears in /data/app/be.thomasmore.powerfactory-2/base.apk)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:299)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at be.thomasmore.powerfactory.MainActivity.onCreate(MainActivity.java:44)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.Activity.performCreate(Activity.java:5990)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.os.Looper.loop(Looper.java:135)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at android.app.ActivityThread.main(ActivityThread.java:5254)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at java.lang.reflect.Method.invoke(Native Method)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at java.lang.reflect.Method.invoke(Method.java:372)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
08-06 08:01:23.770: E/AndroidRuntime(5406):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

昨晚一切都很好。

有什么想法吗?


答案 1

显然,我需要更新我的SDK工具和SDK平台工具,之后我能够选择5.1.1作为我的appcompat v7库项目的构建目标。


答案 2

升级到Android Studio 2.0和Android Support Library 23.3.0后,我遇到了类似的问题。错误是

java.lang.NoSuchFieldError: No static field AppCompatTheme of type

我通过访问Android SDK Manager解决了这个问题。更新可用于以下各项:

  • 安卓 SDK 构建工具
  • 安卓 SDK 工具
  • 安卓支持库
  • 谷歌资料库

更新并再次运行该应用程序,解决了问题。

编辑:

如果您已经更新了上面提到的内容,但仍然存在问题,正如@mparkes在注释中指出的那样,请检查您是否已更新文件以使用最新的库,如下所示:build.gradle(app)

dependencies {
    compile 'com.android.support:appcompat-v7:23.3.0'
}

然后重新生成项目:Build Menu > Rebuild Project


推荐