title: ListView item long click listener throwing a null pointer exception
body: <p>I have a ListView that lists all the files in a folder into the ListView as an array. I seem to have a problem with long selection of the ListView's single item in that, when i long click an exception is thrown that <code> Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference</code>
  I want to achieve a change of color for the selected child view Background and the Text color of the TextView inside that View...
  Here is the complete code i tried to implement my <code>AdapterView.OnLongItemClickListener</code></p>
  <pre><code>public class video_player extends AppCompatActivity implements GestureDetector.OnGestureListener {
      ListView filelist;
      List files;
    @RequiresApi(api = Build.VERSION_CODES.Q)
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.medias_combine);
           filelist = (ListView) findViewById(R.id.filelist);
          files=new ArrayList&lt;&gt;();
          //Defining folder to read files from
          File store = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
            File[] myfiles=store.listFiles();
           //Adding filenames to the ArrayList
          for(int i=0;i&lt;myfiles.length;i++){
           //Adding a file filter
              if(myfiles[i].isFile()&amp;&amp; myfiles[i].getName().contains(&quot;.mp4&quot;)){
                  files.add(myfiles[i].getName());
              }
             //Build the ListView
                ListAdapter myadapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, files);
                  filelist.setAdapter(myadapter);
              //ListView Item long item click listener
               filelist.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                     @Override
                     public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                         for(int i=0;i&lt;filelist.getCount();i++){
                           //Problem is in this loop
                             if(position==id){
                                 view.setBackgroundColor(Color.WHITE);
                                 TextView mytext=(TextView)filelist.getChildAt(position);
                                 mytext.setTextColor(Color.parseColor(&quot;#6600cc&quot;));
                             }else{
                                 view.setBackgroundColor(Color.parseColor(&quot;#6600cc&quot;));
                                 TextView mytext=(TextView)filelist.getItemAtPosition(position);
                               //  TextView text=(TextView)parent.getItemAtPosition(position);
                                 mytext.setTextColor(Color.WHITE);
                             }
                         }
  
                         return true;
                     }
                 });
          }
       }
  </code></pre>