NegativeArraySizeException in Android
<p>I am trying to run this code, but get an error. Can anyone tell me why? The debugger shows the following</p>

<p>Thread [&lt;3> main] (Suspended (exception NegativeArraySizeException)) 
 ViewRoot.handleMessage(Message) line: 1704 
 ViewRoot(Handler).dispatchMessage(Message) line: 99 
 Looper.loop() line: 123 
 ActivityThread.main(String[]) line: 4203 
 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] 
 Method.invoke(Object, Object...) line: 521 
 ZygoteInit$MethodAndArgsCaller.run() line: 791 
 ZygoteInit.main(String[]) line: 549 
 NativeStart.main(String[]) line: not available [native method] </p>

<pre><code>  public void convertAudio () throws IOException {
   Log.d("FILE", "Converting Audio");
   java.io.File fileExist = new java.io.File("/sdcard/" , "test1.3gp");
   java.io.File fileNew = new java.io.File("/sdcard/" , "test2.3gp");
   if (fileNew.exists()) {
    FileInputStream fExist = new FileInputStream(fileExist); 
       FileInputStream fNew = new FileInputStream(fileNew);

       long lengthExist = fileExist.length();
       if (lengthExist &gt; Integer.MAX_VALUE) {
             // File is too large
       }
       byte[] bytesExist = new byte[(int)lengthExist];

       int offset = 0;
       int numRead = 0;
       try {
        while (offset &lt; bytesExist.length &amp;&amp; (numRead=fExist.read(bytesExist, offset, bytesExist.length-offset)) &gt;= 0) {
             offset += numRead;
        }
       } finally {


       }

       // Ensure all the bytes have been read in
       if (offset &lt; bytesExist.length) {
             throw new IOException("Could not completely read file "+fileExist.getName());
       }


       byte[] cleanExist = convert3gpDataToAmr(bytesExist);

       long lengthNew = fileNew.length();
       if (lengthNew &gt; Integer.MAX_VALUE) {
             // File is too large
       }
       byte[] bytesNew = new byte[(int)lengthNew];

       int offsetNew = 0;
       int numReadNew = 0;
       try {
        while (offset &lt; bytesNew.length &amp;&amp; (numRead=fNew.read(bytesNew, offsetNew, bytesNew.length-offsetNew)) &gt;= 0) {
         offsetNew += numReadNew;
        }
        } finally {


        }

       // Ensure all the bytes have been read in
       if (offset &lt; bytesNew.length) {
             throw new IOException("Could not completely read file "+fileExist.getName());
       }


       byte[] cleanNew = convert3gpDataToAmr(bytesNew);       

   }


  }
</code></pre>

<p>// #!AMR\n</p>

<pre><code> private static byte[] AMR_MAGIC_HEADER = {0x23, 0x21, 0x41, 0x4d, 0x52, 0x0a};

  public byte[] convert3gpDataToAmr(byte[] data) {
     if (data == null) {
         return null;
     }

     ByteArrayInputStream bis = new ByteArrayInputStream(data);
         // read FileTypeHeader
     FileTypeBox ftypHeader = new FileTypeBox(bis);
     // You can check if it is correct here
     // read MediaDataHeader
     MediaDataBox mdatHeader = new MediaDataBox(bis);
     // You can check if it is correct here
     int rawAmrDataLength = mdatHeader.getDataLength();
     int fullAmrDataLength = AMR_MAGIC_HEADER.length + rawAmrDataLength;
     byte[] amrData = new byte[fullAmrDataLength];
     System.arraycopy(AMR_MAGIC_HEADER, 0, amrData, 0, AMR_MAGIC_HEADER.length);
         bis.read(amrData, AMR_MAGIC_HEADER.length, rawAmrDataLength);
     return amrData;
 }


}
</code></pre>
