No static field list_container of type I in class Landroid/support/v7/preference/R$id

ぃ、小莉子 提交于 2019-12-08 15:33:36

问题


I migrated a project of 2 years old to Android Studio (and the new lib), I have a lot of problems when I call a PreferenceScreen.

java.lang.NoSuchFieldError: No static field list_container of type I in class Landroid/support/v7/preference/R$id; or its superclasses (declaration of 'android.support.v7.preference.R$id' appears in /data/app/com.sh.inv-1/base.apk)
  at android.support.v7.preference.PreferenceFragmentCompat.onCreateView(PreferenceFragmentCompat.java:260)
  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1988)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:754)
  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1653)
  at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:364)
  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)

My build.gradle is :

apply plugin: 'com.android.application'

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.sh.inv"
        targetSdkVersion 23
        versionCode 66
        versionName "2.5.0"
    }
    buildTypes {
        debug {
        }
        release {
            minifyEnabled true
            proguardFiles 'proguard-project.txt'
        }
    }
    productFlavors {
        dev {
            minSdkVersion 21
        }
        prod {
            minSdkVersion 14
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

repositories {
    maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
}


dependencies {
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')

    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:support-v4:23.2.1'

    compile 'com.android.support:preference-v7:23.2.1'
    compile 'com.android.support:preference-v14:23.2.1'
    compile "com.android.support:appcompat-v7:23.2.1"
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-drive:8.4.0'
    compile 'org.apache.commons:commons-io:+'

    compile 'com.cocosw:undobar:1.8.1@aar'
    compile project(':afilechooser')
    compile project(':simplecropimage')
}

My Fragment is :

public class Settings extends android.support.v7.preference.PreferenceFragmentCompat implements
    OnSharedPreferenceChangeListener {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.settings2);

My AppBaseTheme is :

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
  </style>

I really don't understand how to resolve it. I tried to:

  • delete gradle cache
  • change gradle version (2.10 et 2.12)
  • uses-sdk add: < uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" xmlns:tools="http://schemas.android.com/tools" tools:overrideLibrary="android.support.v14.preference"/>

回答1:


This problem will happen whenever in one application has two files with the same name in two different modules.

For example in a STACK application. 2 modules are there 1. stac1 2. stac2 in stac1->res->layout has miniactivity.xml in stac2->res->layout has miniactivity.xml

then you will get this problem. If you delete any one xml file it will works fine.




回答2:


I finally found the problem. I had a layout which was called preference_list_fragment.xml. It works after deleting the file.



来源:https://stackoverflow.com/questions/36179847/no-static-field-list-container-of-type-i-in-class-landroid-support-v7-preference

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