我正在下载 mp3 文件(使用 asynctask)并更新 Listview 中的进度,其中包含进度条和 textview(显示下载了多少 %)。它运行正常,直到 2% 到 3%,但随后因此异常而崩溃。
这是代码:
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
Log.v("Progress ", Integer.toString(values[0]));
pbar.setProgress(values[0]);
tmin.setText(Integer.toString(values[0]) + "%");
}
这是错误:
07-04 05:50:38.990: E/AndroidRuntime(1587): FATAL EXCEPTION: main
07-04 05:50:38.990: E/AndroidRuntime(1587): java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@40928f80 rejected from java.util.concurrent.ThreadPoolExecutor@40b93700[Running, pool size = 128, active threads = 128, queued tasks = 10, completed tasks = 1]
07-04 05:50:38.990: E/AndroidRuntime(1587): at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1972)
07-04 05:50:38.990: E/AndroidRuntime(1587): at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:787)
07-04 05:50:38.990: E/AndroidRuntime(1587): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1308)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:552)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.os.AsyncTask.execute(AsyncTask.java:499)
07-04 05:50:38.990: E/AndroidRuntime(1587): at MusicDownloader.com.MusicDownloader$CustomAdapter.getView(MusicDownloader.java:209)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.AbsListView.obtainView(AbsListView.java:1949)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.ListView.measureHeightOfChildren(ListView.java:1228)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.ListView.onMeasure(ListView.java:1139)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:956)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.onMeasure(LinearLayout.java:521)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
07-04 05:50:38.990: E/AndroidRuntime(1587): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1889)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.View.measure(View.java:10835)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewRoot.performTraversals(ViewRoot.java:944)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.view.ViewRoot.handleMessage(ViewRoot.java:2046)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.os.Looper.loop(Looper.java:132)
07-04 05:50:38.990: E/AndroidRuntime(1587): at android.app.ActivityThread.main(ActivityThread.java:4123)
07-04 05:50:38.990: E/AndroidRuntime(1587): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 05:50:38.990: E/AndroidRuntime(1587): at java.lang.reflect.Method.invoke(Method.java:491)
07-04 05:50:38.990: E/AndroidRuntime(1587): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-04 05:50:38.990: E/AndroidRuntime(1587): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-04 05:50:38.990: E/AndroidRuntime(1587): at dalvik.system.NativeStart.main(Native Method)
这是获取视图
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.row, parent, false);
ProgressBar pb = (ProgressBar)row.findViewById(R.id.progressbar_Horizontal);
TextView t1 = (TextView)row.findViewById(R.id.minsize);
TextView t2 = (TextView)row.findViewById(R.id.filesize);
t2.setTypeface(tf);
t1.setTypeface(tf);
ImageView btn = (ImageView)row.findViewById(R.id.cancelbtn);
BackgroundAsyncTask bat = new BackgroundAsyncTask(downloadpool.get(position), pb, t1, t2);
if(bat.getStatus() == AsyncTask.Status.PENDING){
// My AsyncTask has not started yet
bat.execute();
}
if(bat.getStatus() == AsyncTask.Status.RUNNING){
// My AsyncTask is currently doing work in doInBackground()
}
if(bat.getStatus() == AsyncTask.Status.FINISHED){
// My AsyncTask is done and onPostExecute was called
}
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Log.e("app", "cancelled...");
//bat.cancel(true);
}
});
return row;
}