title: File extension counter app program ANDROID
body: <p>I was able to make a program to get all the files from my phone's memory and display them in a text field.  </p>
  
  <p>What I am trying to do now is strip off all the file names and count the number of like file extensions.  I tried using map but my program just crashes.  Please help!  I believe that this is coming from a null value inside my string, I tried using the debug in eclipse to see why this was not putting the correct value into the map field but can't see to figure it out.</p>
  
  <p>Thanks</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package com.sdfiletypes;
  
  import java.io.File;
  import java.io.FilenameFilter;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Environment;
  import android.os.StatFs;
  import android.provider.MediaStore.Files;
  import android.util.Log;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
  int myNumber = 0;
  
  String myString;
  private TextView myFileTypes;
      //This is where I put the location of the directory I want it to find
      //I would like this to be recursive but not sure how to change it at this point
  File myFile = new File("/storage/extSdCard/my_pix");
  File[] pictures = myFile.listFiles();
  String[] stringArray;
  String[] newArray;
  Map&lt;String, Integer&gt; myMap;
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      myFileTypes = (TextView) this.findViewById(R.id.textFileType);
  
      String path = Environment.getExternalStorageDirectory().toString();     
  
      stringArray = new String[pictures.length];
  
      for (int i = 0; i &lt; pictures.length; i++)
      {
          stringArray[i] = pictures[i].getName().split("\\.")[1];
  
          if(myMap.containsKey(stringArray[i]))
          {
              myMap.put(stringArray[i], +1);
  
          }
          else
              myMap.put(stringArray[i], 1);
      }
  
      for(Map.Entry&lt;String, Integer&gt; entry: myMap.entrySet())
      {
          String key = entry.getKey();
          Integer value = entry.getValue();
  
          myFileTypes.append(key + " = " + value.toString() + "\n");
      }
  
  }
  
  }
  </code></pre>