美文网首页
常见异常处理方式

常见异常处理方式

作者: Cavabiao | 来源:发表于2015-05-28 19:44 被阅读1741次

1、FragmentTabHost导致的IllegalStateException

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
   at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1375)
   at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1393)
   at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:636)
   at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:615)
   at android.support.v4.app.FragmentTabHost.onAttachedToWindow(FragmentTabHost.java:282)
   at android.view.View.dispatchAttachedToWindow(View.java:11874)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2530)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2537)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1272)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1070)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4296)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
   at android.view.Choreographer.doCallbacks(Choreographer.java:555)
   at android.view.Choreographer.doFrame(Choreographer.java:525)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
   at android.os.Handler.handleCallback(Handler.java:615)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4914)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
   at dalvik.system.NativeStart.main(NativeStart.java)

处理方法:继承FragmentTabHost重写onAttachedToWindow,捕获异常。

2、Unable to add window -- token null is not valid; is your activity running?

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
   at android.view.ViewRootImpl.setView(ViewRootImpl.java:580)
   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
   at android.widget.PopupWindow.invokePopup(PopupWindow.java:1019)
   at android.widget.PopupWindow.showAtLocation(PopupWindow.java:850)
   at android.widget.PopupWindow.showAtLocation(PopupWindow.java:814)
   at com.netease.mail.oneduobaohydrid.command.UICommand$6$1.run(UICommand.java:1005)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5014)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
   at dalvik.system.NativeStart.main(NativeStart.java)

处理方法:继承Activity重写isDestroyed

@Override
public boolean isDestroyed() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return super.isDestroyed();
    } else {
        return mIsDestoryed;// 在onDestroy中设置true
    }
}

在需要显示PopupWindow.showAtLocation之前进行判断!activity.isFinishing() && !activity.isDestroyed()即可。

相关文章

  • 常见异常处理方式

    1、FragmentTabHost导致的IllegalStateException 处理方法:继承Fragment...

  • Springboot异常处理的五种方式

    SpringBoot 框架异常处理有五种处理方式,从范围来说包括有全局异常捕获处理方式和局部异常捕获处理方式,接下...

  • Java学习笔记 17 - 异常及异常处理

    本文主要内容1、异常以及处理方式2、运行时期异常3、方法重写的异常处理4、Throwable类常见方法5、自定义异...

  • Spring Boot异常处理与单元测试

    1.SpringBoot异常处理方式2.SpringBoot单元测试 1.SpringBoot异常处理方式 自定义...

  • Java常用工具_IO流

    1. 异常 1.1 异常的概述 1.2 异常的处理方式 Java中异常的顶层父类是Throwablefinally...

  • 夯实Java基础系列10:深入理解Java中的异常体系

    目录 为什么要使用异常 异常基本定义 异常体系 初识异常 异常和错误 异常的处理方式 "不负责任"的throws ...

  • JVM异常处理

    JVM监控和管理主要针对的是JVM内存溢出问题和性能问题,本篇主要介绍JVM常见的异常处理方式和性能调优。 一、O...

  • JAVA 异常机制

    try-catch 异常机制的本质 异常处理方式 java异常类层次结构图 Error 表明系统JVM已经处于不可...

  • Spring web 异常统一处理

    异常类型 检查异常 检查异常需要捕获或者在函数签名中抛出异常,一般是IO异常,通常处理方式是,如果需要重试则try...

  • 异常的处理方式

    1、抛出 遇到问题不进行具体处理,而是继续抛给调用者(throw,throws) 抛出异常有三种形式,一是thro...

网友评论

      本文标题:常见异常处理方式

      本文链接:https://www.haomeiwen.com/subject/ijufqttx.html