0

I am trying to load names of .mp3 files present in download and music directory with void function, it is showing ("getExternalStoragePublicDirectory" is deprecated):enter image description here

private void fillMusicList()
{
    musicFileList.clear();
    addMusicFilesFrom(String.valueOf(Environment.getExternalStoragePublicDirectory
            (Environment.DIRECTORY_MUSIC)));
    addMusicFilesFrom(String.valueOf(Environment.getExternalStoragePublicDirectory
            (Environment.DIRECTORY_DOWNLOADS)));
}

Error in LogCat:

2020-06-20 17:57:21.220 8383-8383/? E/m.example.muzi: Unknown bits set in runtime_flags: 0x8000
2020-06-20 17:57:22.084 8383-8383/? E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.example.muzik, PID: 8383
 java.lang.RuntimeException: Unable to resume activity 
{com.example.muzik/com.example.muzik.MainActivity}: java.lang.NullPointerException: Attempt to get 
length of null array
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4205)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: java.lang.NullPointerException: Attempt to get length of null array
    at com.example.muzik.MainActivity.addMusicFilesFrom(MainActivity.java:77)
    at com.example.muzik.MainActivity.fillMusicList(MainActivity.java:89)
    at com.example.muzik.MainActivity.onResume(MainActivity.java:109)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
    at android.app.Activity.performResume(Activity.java:7939)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237) 
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7356) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
Mr-JP
  • 17
  • 1
  • 3
  • What variable has a null value when the code on line 77 is executed? – NormR Jun 20 '20 at 14:14
  • https://imgur.com/a/ecoiH5I – Mr-JP Jun 20 '20 at 14:17
  • Don't post pictures of text. Instead, cut and paste the text into your question by clicking the edit link at the bottom of the question. Check the value of `musicDir.listFiles()` with your debugger or a `System.out.println()`. It's likely to be null. – MarsAtomic Jun 20 '20 at 15:39
  • Ohk sorry I am not familiar with site I will update through edit link. – Mr-JP Jun 20 '20 at 16:10
  • Yes it is showing null. Could ("getExternalStoragePublicDirectory" is deprecated) this be problem why musicDir.listFiles() is showing null – Mr-JP Jun 20 '20 at 16:11
  • Deprecated has nothing to do with it. Look up "deprecated" online and you'll see why. – MarsAtomic Jun 22 '20 at 00:46

0 Answers0