publishProgress()导致崩溃

时间:2013-06-24 20:22:05

标签: java android compiler-errors download

当我尝试下载文件时,应用程序崩溃了。 问题是当我刷新进度条时。我使用了asynctask.T错误就在于:

while ((read = is.read(buffer, 0, 1024)) > 0) {

                    totalRead += read;
                    //System.out.println(totalRead);
                    String progress = ("" + ((int) (totalRead * 100)) / lenghtOfFile);
                    System.out.println(progress);
      /Here/      publishProgress(progress);

                    cos.write(buffer, 0, read);
                }

logcat的:

W/Bundle: Attempt to cast generated internal exception:
        java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at android.os.Bundle.getInt(Bundle.java:940)
        at com.android.server.am.MultiWindowManagerService.getDefaultWindowInfoLocked(MultiWindowManagerService.java:479)
        at com.android.server.am.MultiWindowManagerService.addWindowInfo(MultiWindowManagerService.java:317)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2394)
        at com.android.server.am.ActivityStack.startActivityUncheckedLocked(ActivityStack.java:3782)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3377)
        at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3946)
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2651)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:148)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1734)
        at android.os.Binder.execTransact(Binder.java:367)
        at dalvik.system.NativeStart.run(Native Method)
06-24 22:13:21.541    2271-2807/?                              W/Bundle: Key com.sec.android.multiwindow.DEFAULT_SIZE_H expected Integer but value was a java.lang.String.  The default value 0 was returned.
06-24 22:13:21.546    2654-2654/?                              W/ResourceType: Attempt to retrieve bag 0x01030068 which is invalid or in a cycle.
06-24 22:13:21.546    2271-2807/?                              W/Bundle: Attempt to cast generated internal exception:
        java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at android.os.Bundle.getInt(Bundle.java:940)
        at com.android.server.am.MultiWindowManagerService.getDefaultWindowInfoLocked(MultiWindowManagerService.java:483)
        at com.android.server.am.MultiWindowManagerService.addWindowInfo(MultiWindowManagerService.java:317)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2394)
        at com.android.server.am.ActivityStack.startActivityUncheckedLocked(ActivityStack.java:3782)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3377)
        at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3946)
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2651)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:148)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1734)
        at android.os.Binder.execTransact(Binder.java:367)
        at dalvik.system.NativeStart.run(Native Method)
06-24 22:13:21.546    2271-2807/?                              W/Bundle: Key com.sec.android.multiwindow.MINIMUM_SIZE_W expected Integer but value was a java.lang.String.  The default value 0 was returned.
06-24 22:13:21.551    2271-2807/?                              W/Bundle: Attempt to cast generated internal exception:
        java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at android.os.Bundle.getInt(Bundle.java:940)
        at com.android.server.am.MultiWindowManagerService.getDefaultWindowInfoLocked(MultiWindowManagerService.java:488)
        at com.android.server.am.MultiWindowManagerService.addWindowInfo(MultiWindowManagerService.java:317)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2394)
        at com.android.server.am.ActivityStack.startActivityUncheckedLocked(ActivityStack.java:3782)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3377)
        at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3946)
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2651)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:148)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1734)
        at android.os.Binder.execTransact(Binder.java:367)
        at dalvik.system.NativeStart.run(Native Method)
06-24 22:13:21.551    2271-2807/?                              W/Bundle: Key com.sec.android.multiwindow.MINIMUM_SIZE_H expected Integer but value was a java.lang.String.  The default value 0 was returned.
06-24 22:13:21.551    2271-2807/?                              W/Bundle: Attempt to cast generated internal exception:
        java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at android.os.Bundle.getInt(Bundle.java:940)
        at com.android.server.am.MultiWindowManagerService.getDefaultWindowInfoLocked(MultiWindowManagerService.java:492)
        at com.android.server.am.MultiWindowManagerService.addWindowInfo(MultiWindowManagerService.java:317)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2394)
        at com.android.server.am.ActivityStack.startActivityUncheckedLocked(ActivityStack.java:3782)
        at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3377)
        at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3946)
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2651)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:148)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1734)
        at android.os.Binder.execTransact(Binder.java:367)
        at dalvik.system.NativeStart.run(Native Method)

2 个答案:

答案 0 :(得分:0)

我猜你试图更改doInBackground中的用户界面(查看元素),你必须在onPostExecute

中更改它

但只有当您显示publishProgress的代码时,我们才能确定找到它。

答案 1 :(得分:0)

似乎您的异步任务使用Integer来发布进度(给予异步任务的第二个泛型类型),您应该将其更改为:

int progress = (int)((totalRead * 100) / lenghtOfFile);

或者您可以将第二个通用类型更改为String