java - 哪个引用变量为空 - 尝试从空对象引用的字段 'android.os.Handler android.support.v4.a.m.a' 读取

标签 java android

我有一个堆栈跟踪,但不清楚哪个引用变量为空。

尝试从字段 'android.os.Handler android.support.v4.a.m.a' 读取空对象引用

if (Looper.myLooper() != mActivity.mHandler.getLooper()) {

(我的意见是 mActivity 为空)

  1. mActivity 为空?
  2. mHandler 为空?

更完整的堆栈跟踪 - 但不是问题的一部分......................

D/AndroidRuntime( 8354): Shutting down VM
E/AndroidRuntime( 8354): FATAL EXCEPTION: main
E/AndroidRuntime( 8354): Process: za.co.nedsecure.nedbankROA.ete, PID: 8354
E/AndroidRuntime( 8354): java.lang.NullPointerException: Attempt to read from field 'android.os.Handler android.support.v4.a.m.a' on a null object reference
E/AndroidRuntime( 8354):at android.support.v4.a.s.f(FragmentManager.java:1476)
E/AndroidRuntime( 8354):at android.support.v4.a.s.b(FragmentManager.java:490)
E/AndroidRuntime( 8354):at xyz.......MainActivity.a(MainActivity.java:299)

MainActivity 代码为:

if (mainActivityWeakReference.get() != null) {
                    mainActivityWeakReference.get().getSupportFragmentManager().executePendingTransactions();
                }

我的修复:(我希望就是这样)

if (mainActivityWeakReference.get() != null && !mainActivityWeakReference.get().isFinishing()) {
                    mainActivityWeakReference.get().getSupportFragmentManager().executePendingTransactions();
                }

最佳答案

您必须阅读更多堆栈跟踪以获取更多线索,但真正找到这些线索的最简单方法是将表达式放在多行中。

if (Looper
  .myLooper() 
  != 
  mActivity
  .mHandler
  .getLooper()) {

请记住在提交源之前撤消此操作。

关于java - 哪个引用变量为空 - 尝试从空对象引用的字段 'android.os.Handler android.support.v4.a.m.a' 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35749270/

相关文章:

java - 如何在 Java 中比较字符串?

java - 在 Eclipse IProject 中获取 src 目录?

Java正则表达式

java - 在应用程序级别处理数据库崩溃

android - VideoView 错误 "Access denied finding property"

java - 如何反序列化avro文件

Android 自定义微调适配器不显示内容

android - 从 QuickBlox 聊天室收到的消息中的数据包 ID 为空

android - aapt 错误获取 'android:name' 属性 : attribute is not a string value

android - 更改 Eclipse Android 项目中的源路径