我正在开发一个Android项目,我需要将一个mp3文件发布到PHP服务器。当mp3文件很小时,我可以将它成功发布到服务器,但是当mp3文件大小为3-4 MB时,我在名字对中出错。在这里我发布我的错误和代码。可能是什么问题?
以下代码适用于onActivityResult(),我将mp3文件转换为Base64格式。
if (resultCode == RESULT_OK) {
if (requestCode == RQS_OPEN_AUDIO_MP3) {
Uri audioFileUri = data.getData();
Toast.LENGTH_LONG).show();
Log.e("Mp3 Path==>", data.getData() + "");
Log.e("Mp3 URI==>", audioFileUri + "");
String path = ConstantData.getPath(this, audioFileUri);
File file = new File(path);
Log.e("File Length==>", file.length() + "");
b=null;
b= new byte[(int) file.length()];
fileInputStream=null;
encode=null;
fileInputStream = new FileInputStream(file);
fileInputStream.read(b);
fileInputStream.close();
encode = Base64.encodeBytes(b);
//Log.e("Mp3 Encoded==>", encode + "");
showImagePostingDialog("Upload?", "You want To Upload this Mp3 File?", null);
}
}
这是我在NameValuePair Log
收到的错误doInBackground()
。
10-01 10:35:15.420: E/AndroidRuntime(13428): FATAL EXCEPTION: AsyncTask #5
10-01 10:35:15.420: E/AndroidRuntime(13428): java.lang.RuntimeException: An error occured while executing doInBackground()
10-01 10:35:15.420: E/AndroidRuntime(13428): at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-01 10:35:15.420: E/AndroidRuntime(13428): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.lang.Thread.run(Thread.java:841)
10-01 10:35:15.420: E/AndroidRuntime(13428): Caused by: java.lang.OutOfMemoryError
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:132)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.lang.StringBuilder.append(StringBuilder.java:124)
10-01 10:35:15.420: E/AndroidRuntime(13428): at libcore.net.UriCodec.appendEncoded(UriCodec.java:119)
10-01 10:35:15.420: E/AndroidRuntime(13428): at libcore.net.UriCodec.encode(UriCodec.java:133)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.net.URLEncoder.encode(URLEncoder.java:57)
10-01 10:35:15.420: E/AndroidRuntime(13428): at org.apache.http.client.utils.URLEncodedUtils.encode(URLEncodedUtils.java:184)
10-01 10:35:15.420: E/AndroidRuntime(13428): at org.apache.http.client.utils.URLEncodedUtils.format(URLEncodedUtils.java:163)
10-01 10:35:15.420: E/AndroidRuntime(13428): at org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:71)
10-01 10:35:15.420: E/AndroidRuntime(13428): at com.android.fikra.events.eventslast.EventLastActivity$BackGroundTaskPostMp3.doInBackground(EventLastActivity.java:1060)
10-01 10:35:15.420: E/AndroidRuntime(13428): at com.android.fikra.events.eventslast.EventLastActivity$BackGroundTaskPostMp3.doInBackground(EventLastActivity.java:1)
10-01 10:35:15.420: E/AndroidRuntime(13428): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-01 10:35:15.420: E/AndroidRuntime(13428): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-01 10:35:15.420: E/AndroidRuntime(13428): ... 4 more