Please I need assistance. I was creating a youtube downloader app, after launch on my device, It displayed application error. I traces the error message from logcat.
2021-12-14 05:21:17.718 9291-9291/com.android.youtubedownloader E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.youtubedownloader, PID: 9291
java.lang.ClassCastException: android.hardware.display.DisplayManager cannot be cast to android.app.DownloadManager
at com.android.youtubedownloader.MainActivity$1.onUrisAvailable(MainActivity.java:46)
at at.huber.youtubeExtractor.YouTubeUriExtractor.onExtractionComplete(YouTubeUriExtractor.java:15)
at at.huber.youtubeExtractor.YouTubeExtractor.onPostExecute(YouTubeExtractor.java:146)
at at.huber.youtubeExtractor.YouTubeExtractor.onPostExecute(YouTubeExtractor.java:38)
at android.os.AsyncTask.finish(AsyncTask.java:660)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6275)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
CodePudding user response:
This is due to you're trying to cast DisplayManager object to DownloadManager which is not possible to solve this you need to do like following.
Java
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Kotlin
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager