title: Causedby:java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter' on a null object reference
body: <h1>DisplayActivity.java</h1>
  <p>I'm relatively new to android.I am trying to make a list view that contains music.The app is perfectly build but then when i try to run it on the device it crashes.I try to debug the app and it gave me the above error.Here are my following code</p>
  <pre><code>package com.bytetex.azmusic;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.Manifest;
  import android.os.Bundle;
  import android.os.Environment;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  
  import com.karumi.dexter.Dexter;
  import com.karumi.dexter.PermissionToken;
  import com.karumi.dexter.listener.PermissionDeniedResponse;
  import com.karumi.dexter.listener.PermissionGrantedResponse;
  import com.karumi.dexter.listener.PermissionRequest;
  import com.karumi.dexter.listener.single.PermissionListener;
  
  import java.io.File;
  import java.util.ArrayList;
  
  public class DisplayActivity extends AppCompatActivity {
  
      private String[] itemsAll;
      private ListView mSongsLists;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_display);
          appExternalStorageStoragePermission();
          mSongsLists=findViewById(R.id.songLists);
      }
  
      public void appExternalStorageStoragePermission() {
          Dexter.withContext(this)
                  .withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                  .withListener(new PermissionListener() {
                      @Override
                      public void onPermissionGranted(PermissionGrantedResponse response) {
                          dispalyAudioSongName();
  
                      }
  
                      @Override
                      public void onPermissionDenied(PermissionDeniedResponse response) {
  
                      }
  
                      @Override
                      public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
                          token.continuePermissionRequest();
  
                      }
                  }).check();
      }
  
      public ArrayList&lt;File&gt; readOnluAudioSongs(File file) {
          ArrayList&lt;File&gt; arrayList = new ArrayList&lt;&gt;();
          File[] allFiles = file.listFiles();
          assert allFiles != null;
          for (File individualFile : allFiles) {
              if (individualFile.isDirectory() &amp;&amp; !individualFile.isHidden()) {
                  arrayList.addAll(readOnluAudioSongs(individualFile));
              } else {
                  if (individualFile.getName().endsWith(&quot;.mp3&quot;) || individualFile.getName().endsWith(&quot;.aac&quot;) || individualFile.getName().endsWith(&quot;.wav&quot;) || individualFile.getName().endsWith(&quot;.wma&quot;)) {
                      {
                          arrayList.add(individualFile);
                      }
                  }
              }
  
          }
          return arrayList;
      }
      private void dispalyAudioSongName()
      {
          final ArrayList&lt;File&gt; audioSong= readOnluAudioSongs(Environment.getExternalStorageDirectory());
          itemsAll=new String[audioSong.size()];
          for (int songCounter=0; songCounter&lt;audioSong.size(); songCounter++)
          {
              itemsAll[songCounter]=audioSong.get(songCounter).getName();
          }
          ArrayAdapter&lt;String&gt; arrayAdapter=new ArrayAdapter&lt;String&gt;(DisplayActivity.this, android.R.layout.simple_list_item_1, itemsAll);
          mSongsLists.setAdapter(arrayAdapter);
      }
  }
  </code></pre>
  <h1>activity_display.xml</h1>
  <p>here is my xml code</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.DisplayActivity&quot;&gt;
  
      &lt;ListView
          android:id=&quot;@+id/songLists&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  &lt;/ListView&gt;
  
  
  &lt;/RelativeLayout&gt;
  
  
  </code></pre>