Это мой код. Я получаю FileNotFoundException для getAssets () ?. openFd (sf.path)? но этот файл существует!
fun addSong(sf: File){
val fd0 = context?.getAssets()?.openFd(sf.path)?.getFileDescriptor()
val mmr = MediaMetadataRetriever()
mmr.setDataSource(fd0)
val s = Song()
s.file = sf
s.album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
allsongs = allsongs.plusElement(s)
}
class Song{
var file: File? = null
var album: String
}
Вот трассировка стека
E/AndroidRuntime: FATAL EXCEPTION: main
Process: filodev.com.musicplayer, PID: 21382
java.lang.RuntimeException: Unable to start activity ComponentInfo{filodev.com.musicplayer/filodev.com.musicplayer.MainActivity}: java.io.FileNotFoundException: filename
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2830)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1606)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.io.FileNotFoundException: filename
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:390)
at filodev.com.musicplayer.FileFinder.addSong(FileFinder.kt:54)
at filodev.com.musicplayer.FileFinder.startFind(FileFinder.kt:48)
at filodev.com.musicplayer.FileFinder.startFind(FileFinder.kt:43)
at filodev.com.musicplayer.FileFinder.startFind(FileFinder.kt:43)
at filodev.com.musicplayer.FileFinder.startFind(FileFinder.kt:43)
at filodev.com.musicplayer.FileFinder.find(FileFinder.kt:34)
at filodev.com.musicplayer.MainActivity.checkPermission(MainActivity.kt:35)
at filodev.com.musicplayer.MainActivity.onCreate(MainActivity.kt:23)
at android.app.Activity.performCreate(Activity.java:7016)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2783)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1606)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:169)
at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Я уже добавил разрешение на чтение и запись во внешнем хранилище в манифесте.
Почему я получаю это исключение, если файл существует?