Toast消失后,应用程序崩溃

时间:2015-05-27 12:37:20

标签: android crash logcat android-toast

我有一个从互联网上播放流的Android应用程序。当没有可播放的流时,应用程序应显示Toast并显示以下消息:“视频无法播放”,屏幕应为黑色。当在4.2 Android机器上试试这些应用程序时一切都没问题,但在4.4安卓机器人盒上,在Toast消失后,应用程序崩溃了。 这是显示Toast的代码:

public void setOnErrorListener(){

        OnErrorListener oel = new OnErrorListener(){

            @Override
            public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
                log.i("TiboVideoView-","error");
                //catchupVideoView.unlockPlayer();

                //Toast.makeText(context,context.getString(R.string.videoerror), Toast.LENGTH_LONG).show();

                nowPlayingDate.setTime(standartTime.getTime());
                nextPlayingDate = null;

                    try {
                        if (isPlaying()) {
                            try {                       
                                stopPlayback(); 
                            } catch (Exception f) {
                            }
                        }
                    } catch (Exception g) {
                    }


                    try{
                    handler.post(LOG_CHANNEL_LOGS);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }

                try
                {
                Toast.makeText(context,context.getString(R.string.videoerror), Toast.LENGTH_LONG).show();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
                return true;
            }

        };

        super.setOnErrorListener(oel);
    }

这是Logcat的输出:

    05-26 10:02:27.316 E/MediaPlayer( 2047): Error (-32,0)
        05-26 10:02:27.316 D/VideoView( 2047): Error: -32,0
        05-26 10:02:27.316 I/hide    ( 2047): 8
        05-26 10:02:27.316 I/TiboVideoView-( 2047): error
        05-26 10:02:27.316 D/AndroidRuntime( 2047): Shutting down VM
        05-26 10:02:27.316 W/dalvikvm( 2047): threadid=1: thread exiting with uncaught exception (group=0x41728ba8)
        05-26 10:02:27.316 E/NotificationService(  516): Package has already posted 50 toasts. Not showing more. Package=com.tibo.webtv
        05-26 10:02:27.316 E/NotificationService(  516): Package has already posted 50 toasts. Not showing more. Package=com.tibo.webtv
        05-26 10:02:27.326 I/Process ( 2047): Sending signal. PID: 2047 SIG: 9
        05-26 10:02:27.326 E/AndroidRuntime( 2047): FATAL EXCEPTION: main
        05-26 10:02:27.326 E/AndroidRuntime( 2047): Process: com.tibo.webtv, PID: 2047
        05-26 10:02:27.326 E/AndroidRuntime( 2047): java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@42669c68 rejected from java.util.concurrent.ThreadPoolExecutor@4186cfd8[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 36]
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.tibo.webtv.catchup.am.run(Unknown Source)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Handler.handleCallback(Handler.java:733)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Handler.dispatchMessage(Handler.java:95)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.os.Looper.loop(Looper.java:136)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at android.app.ActivityThread.main(ActivityThread.java:5017)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.lang.reflect.Method.invokeNative(Native Method)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at java.lang.reflect.Method.invoke(Method.java:515)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
        05-26 10:02:27.326 E/AndroidRuntime( 2047):     at dalvik.system.NativeStart.main(Native Method)
        05-26 10:02:27.326 W/ActivityManager(  516):   Force finishing activity com.tibo.webtv/.catchup.CatchupActivity
        05-26 10:02:27.426 D/ActivityManager(  516): send app_CRASH broadcast, packageName:com.tibo.webtv
        05-26 10:02:27.426 W/InputDispatcher(  516): channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
        05-26 10:02:27.426 E/InputDispatcher(  516): channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
        05-26 10:02:27.426 W/InputDispatcher(  516): channel '41c803b0 Toast (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
        05-26 10:02:27.426 E/InputDispatcher(  516): channel '41c803b0 Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
        05-26 10:02:27.426 W/InputDispatcher(  516): Attempted to unregister already unregistered input channel '41b17380 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity (server)'
        05-26 10:02:27.426 W/InputDispatcher(  516): Attempted to unregister already unregistered input channel '41c803b0 Toast (server)'
        05-26 10:02:27.426 I/ActivityManager(  516): Process com.tibo.webtv (pid 2047) has died.
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41c44f98 u0 com.tibo.webtv/com.tibo.webtv.MainActivity}
        05-26 10:02:27.426 W/ContextImpl(  516): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1162 com.android.server.am.ActivityManagerService.onVideoPlayerCrashed:3700 com.android.server.am.ActivityManagerService.handleAppDiedLocked:3730 com.android.server.am.ActivityManagerService.appDiedLocked:3868 com.android.server.am.ActivityManagerService$AppDeathRecipient.binderDied:1046 
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41b17380 u0 com.tibo.webtv/com.tibo.webtv.catchup.CatchupActivity}
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41c803b0 u0 Toast}
        05-26 10:02:27.426 I/WindowState(  516): WIN DEATH: Window{41beb378 u0 SurfaceView}
        05-26 10:02:27.436 I/ActivityManager(  516): Start proc com.tibo.webtv for activity com.tibo.webtv/.MainActivity: pid=2235 uid=10058 gids={50058, 3003, 1028, 1015}
        05-26 10:02:27.536 D/dalvikvm( 2235): GC_CONCURRENT freed 217K, 26% free 710K/952K, paused 1ms+0ms, total 5ms
        05-26 10:02:27.566 D/dalvikvm(  516): GC_CONCURRENT freed 1407K, 26% free 6296K/8484K, paused 2ms+6ms, total 55ms
        05-26 10:02:27.566 D/dalvikvm(  516): WAIT_FOR_CONCURRENT_GC blocked 38ms
        05-26 10:02:27.586 D/dalvikvm( 2235): GC_CONCURRENT freed 178K, 18% free 948K/1152K, paused 0ms+4ms, total 9ms
        05-26 10:02:27.736 D/dalvikvm( 2235): GC_CONCURRENT freed 192K, 16% free 1149K/1368K, paused 2ms+2ms, total 10ms
        05-26 10:02:27.916 D/dalvikvm(  516): GC_CONCURRENT freed 1350K, 27% free 6276K/8484K, paused 1ms+6ms, total 42ms
        05-26 10:02:27.956 D/dalvikvm( 2235): GC_FOR_ALLOC freed 21K, 11% free 1222K/1368K, paused 4ms, total 4ms
        05-26 10:02:27.966 I/dalvikvm-heap( 2235): Grow heap (frag case) to 10.004MB for 9216016-byte allocation
        05-26 10:02:27.976 D/dalvikvm( 2235): GC_CONCURRENT freed <1K, 2% free 10222K/10372K, paused 0ms+1ms, total 4ms
        05-26 10:02:28.066 D/TextLayoutCache( 2235): Using debug level = 0 - Debug Enabled = 0
        05-26 10:02:28.126 W/Settings( 2235): Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.
        05-26 10:02:28.136 W/ActivityThread( 2235): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(ge

tClass().getClassLoader());

有人理解为什么会这样吗?

2 个答案:

答案 0 :(得分:2)

尝试看一下:Avoiding RejectedExecutionException in Android 4.4 when app uses list。我正在写下接受的答案:

  

问题在于AsyncTask使用的不同执行程序   取决于应用的targetSdkVersion:

     

1)targetSdkVersion&lt; = 12

     

AsyncTask.execute()使用AsyncTask.THREAD_POOL_EXECUTOR。队列   在AsyncTask.THREAD_POOL_EXECUTOR中限制为128个项目。如果   queue is full抛出RejectedExecutionException。这是什么   发生在这里

     

2)targetSdkVersion&gt; 12

     

AsyncTask使用AsyncTask.SERIAL_EXECUTOR。   AsyncTask.SERIAL_EXECUTOR具有无界队列。所以在这种情况下   永远不会抛出RejectedExecutionException。

     

解决方案1(AKA&#34; clean&#34;解决方案)

     

使用单独的APK与targetSdkVersion&gt; 12和更高版本的代码   所以这对于HONEYCOMB_MR2和更高版本的Android来说是首选。   这将导致AsyncTask使用ThreadPool.SERIAL_EXECUTOR   HONEYCOMB_MR2及更高版本的Android。

     

解决方案2(AKA the dirty hack)

     

使用Reflection。将AsyncTask.SERIAL_EXECUTOR设为默认值。

     

AsyncTask.class.getMethod(&#34; setDefaultExecutor&#34;,Executor.class).invoke(null,AsyncTask.SERIAL_EXECUTOR);

当然,我需要查看您的代码,以了解如何解决您的问题。

EDIT。 首先检查context是否为空...顺便问一下,你能发布整个AsyncTask吗?

答案 1 :(得分:0)

这个:http://developer.android.com/reference/java/util/concurrent/RejectedExecutionException.html说,“当一个任务无法被接受执行时,执行者抛出异常。”

另外我注意到了这一点:Package has already posted 50 toasts.两次。该代码应该显示100个祝酒词?

你也应该展示一些代码。一个例外总是有点神秘。