您好,我正在尝试在回收站视图中加载我的设备上的mp3歌曲,我收到了java.lang.NoSuchMethodError

时间:2018-03-27 06:42:42

标签: android

请告诉我出了什么问题。我似乎无法理解它。这是完整的错误堆栈,在此下面我添加了build.gradle文件。请解释导致错误的原因。谢谢。

        java.lang.NoSuchMethodError: android.support.v4.content.res.ResourcesCompat.getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface;
            at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
            at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
            at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
            at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
            at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:81)
            at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
            at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
            at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:215)
            at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:218)
            at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:336)
            at android.view.BridgeInflater.onCreateView(BridgeInflater.java:155)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
            at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:225)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
            at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
            at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at com.android.layoutlib.bridge.bars.CustomBar.<init>(CustomBar.java:90)
            at com.android.layoutlib.bridge.bars.StatusBar.<init>(StatusBar.java:67)
            at com.android.layoutlib.bridge.impl.Layout.createStatusBar(Layout.java:245)
            at com.android.layoutlib.bridge.impl.Layout.<init>(Layout.java:156)
            at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:288)
            at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
            at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
            at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
            at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)

Build.gradle文件:

apply plugin: 'com.android.application'  
android {  
    compileSdkVersion 26  
    defaultConfig {  
        applicationId "com.example.dell.musicplayer"  
        minSdkVersion 21  
        targetSdkVersion 26  
        versionCode 1  
        versionName "1.0"  
        testInstrumentationRunner  
        "android.support.test.runner.AndroidJUnitRunner"  
    }  
    buildTypes {  
        release {  
            minifyEnabled false  
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
            'proguard-rules.pro'  
        }  
    }  
}  
dependencies {  
    implementation fileTree(dir: 'libs', include: ['*.jar'])  
    implementation 'com.android.support:appcompat-v7:26.1.0'  
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'  
    testImplementation 'junit:junit:4.12'  
    androidTestImplementation 'com.android.support.test:runner:1.0.1'  
    androidTestImplementation 'com.android.support.test.espresso:espresso- 
    core:3.0.1'  
    compile 'com.jakewharton:butterknife:8.8.1'  
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'  
    compile 'com.android.support:recyclerview-v7:26.1.0'  
    compile 'com.android.support:cardview-v7:26.1.0'  
    implementation 'com.github.bumptech.glide:glide:4.6.1'    
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'  
}

同样在我的布局中,我收到以下警告:

  

无法实例化以下类:    - android.support.v7.widget.AppCompatTextView(Open Class,Show Exception,Clear Cache)提示:在自定义中使用View.isInEditMode()   视图在IDE中显示时跳过代码或显示示例数据。如果这   是一个意外的错误,你也可以尝试建立项目,然后   手动刷新布局。

1 个答案:

答案 0 :(得分:1)

以下问题:

java.lang.NoSuchMethodError: android.support.v4.content.res.ResourcesCompat.getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface;

可能是因为Glide严格使用支持库26.1.0中不存在的功能。 Glide正在使用支持library 27.1.0。这似乎与ResourceCompat.getFont()有关,它从支持库27.1.0开始存在。

尝试将您的compileSdkVersiontargetSdkVersion更新为 27 。并将所有支持库更改为 27.1.0