How to fix stringIndexOutOfBoundsExceptipon on android? : My app record camera preview every 5 minute.
record file is save on `/sdcard/Movies/*.mp4`

before create record file. check current storage space 

    //execute every 5 minute.
    if (current space < MAX_SIZE) { //record start
          //record start
    } else { //record impossible. try old file delete.
         RecordFile recFile = new RecordFile();
         boolean ret = recFile.deleteOldFile();
    }

my situation current record impossible. try old file delete.
but occur `StringIndexOutOfBoundsException` 

my source

RecordFile.class

    private ArrayList<String> mRecFiles;
    private ArrayList<Long> mRecFilesNum;
    private HashMap<Long, String> fileMap;
    private String filePath;
    private String delFileName;

    public boolean deleteOldFile() {
          String delFname = getRecordFileList();
          File delFile = new File(filePath + delFname);
          if (delFile.delete()) {
                 //success old file delete
                 return true;
          } else {
                //fail delete
                return true;
          }
    }

    public String getRecordFileList() {
          filePath = Environment.getExternalStorageDirectory() + File.separator
                + Environment.DIRECTORY_MOVIES + File.separator;

        mRecFiles = new ArrayList();
        mRecFilesNum = new ArrayList();

        fileMap = new HashMap();

        File file = new File(filePath);
        File[] list = file.listFiles();

        for (int i = 0; i < list.length; i++) {
            String fname = list[i].getName();

            int idx = fname.lastIndexOf(".");
            String fname2 = fname.substring(0, idx);   //occur stringIndexOutOfBoundsException

            long tmp = Long.parseLong(fname2.replaceAll("[^0-9]", ""));
       
            fileMap.put(tmp, fname);
            mRecFilesNum.add(tmp);
        }

        long max = Collections.max(mRecFilesNum);
        long min = Collections.min(mRecFilesNum);
        Iterator<Long> iterator = fileMap.keySet().iterator();
        while (iterator.hasNext()) {
            Long key = iterator.next();
    
            if (key == min) {
                delFileName = fileMap.get(key);

                break;
            }
        }

        return delFileName;
    }
}


    java.lang.StringIndexOutOfBoundsException: length=10; regionStart=0; regionLength=-1
              at java.lang.String.startEndAndLength(String.java:298)
              at java.lang.String.substring(String.java:1087)
              at kr.co.iosystem.blackeyeonandroid.record.RecordFile.getRecordFileList(RecordFile.java:72)
              at kr.co.iosystem.blackeyeonandroid.record.RecordFile.deleteBeforeFile(RecordFile.java:35)
              at kr.co.iosystem.blackeyeonandroid.BlackEyeActivity$mRecTimerHandler.handleMessage(BlackEyeActivity.java:582)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5415)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

 
How to fix this problem?
thanks.
