简体   繁体   English

异常 java.lang.NoClassDefFoundError

[英]Exception java.lang.NoClassDefFoundError

I'm new to app development.我是应用程序开发的新手。 I got this error in my published app on Play store.我在 Play 商店发布的应用程序中出现此错误。 Google play console tracked this below error in the crash details section. Google Play 控制台在崩溃详细信息部分跟踪了以下错误。 Because of this error my app is getting bad behaviour status on play console.由于这个错误,我的应用程序在 Play 控制台上出现不良行为状态。 This error came on Android SDK 25 and below.此错误出现在 Android SDK 25 及以下。 Can anyone please show the proper full method for audio focus request in a media player where audio is played and paused from the main screen and notification area.任何人都可以在从主屏幕和通知区域播放和暂停音频的媒体播放器中展示音频焦点请求的正确完整方法。 Also the audio is stored in the raw folder locally.音频也存储在本地的原始文件夹中。

 Exception java.lang.NoClassDefFoundError: Failed resolution of: Landroid/media/AudioFocusRequest$Builder;
  at com.onestopstudio.sankatmochanhanuman.SankatMochanHanuman.onCreate (SankatMochanHanuman.java:197)
  at android.app.Activity.performCreate (Activity.java:6977)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2946)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3064)
  at android.app.ActivityThread.-wrap14 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1659)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6816)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1565)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1453)
Caused by java.lang.ClassNotFoundException:
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:380)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)

Here is the code below I'm using for audio focus request.下面是我用于音频焦点请求的代码。 This code is also shown in GeekForGeeks How to Manage Audio Focus in Android?这段代码在GeekForGeeks How to Manage Audio Focus in Android? question.问题。 Here is the link for GeekForGeeks topic page:- https://www.geeksforgeeks.org/how-to-manage-audio-focus-in-android这是 GeekForGeeks 主题页面的链接:- https://www.geeksforgeeks.org/how-to-manage-audio-focus-in-android

 audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    playbackAttributes = new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
            .build();

    AudioFocusRequest focusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
            .setAudioAttributes(playbackAttributes)
            .setAcceptsDelayedFocusGain(true)
            .setOnAudioFocusChangeListener(audioFocusChangeListener)
            .build();
    audioFocusRequest = audioManager.requestAudioFocus(focusRequest);
    audioManager.abandonAudioFocus(audioFocusChangeListener);

You should use AudioFocusRequest.Builder on Android 8.0 (API level 26) and higher or try to use compat version: add this to your build.gradle :您应该在 Android 8.0(API 级别 26)及更高版本上使用AudioFocusRequest.Builder或尝试使用兼容版本:将此添加到您的build.gradle

dependencies {
   implementation "androidx.media:media:1.6.0"
}

And use AudioFocusRequestCompat.Builder instead of AudioFocusRequest.Builder并使用AudioFocusRequestCompat.Builder而不是AudioFocusRequest.Builder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM