• Android log 引发的血案


    今天调试代码,我打印了一个东西:

            Log.d("WelcomeActivity", res.str);
    

    结果总是代码执行不到这一行的下一行,程序也没有挂掉。后来,我自己去想各种可能,什么情况程序没有执行下去呢?难道我打印一个log 也会出问题?我想断点看看这个res.str 是什么东西。

    结果一看是null,然后我就测试一下,打印 null 试一下:

            Log.d("WelcomeActivity", null);
    

    结果

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.****r/com.**.iR***.ui.activity.WelcomeActivity}: java.lang.NullPointerException: println needs a message
                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2830)
                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2891)
                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1628)
                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                           at android.os.Looper.loop(Looper.java:185)
                                                           at android.app.ActivityThread.main(ActivityThread.java:6522)
                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
                                                        Caused by: java.lang.NullPointerException: println needs a message
                                                           at android.util.Log.println_native(Native Method)
                                                           at android.util.Log.d(Log.java:175)
                                                           at com.chaozh.iReader.ui.activity.WelcomeActivity.onCreate(WelcomeActivity.java:96)
                                                           at android.app.Activity.performCreate(Activity.java:6967)
                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2783)
                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2891) 
                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1628) 
                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                           at android.os.Looper.loop(Looper.java:185) 
                                                           at android.app.ActivityThread.main(ActivityThread.java:6522) 
                                                           at java.lang.reflect.Method.invoke(Native Method)

    啊,以后打印东西,要注意啊。不能大意!

  • 相关阅读:
    Unity NPOI 无法读取xlsx
    spring源码之—Assert.notNull
    手工Ghost安装系统
    一键GHOST优盘版安装XP/win7系统
    oncontextmenu事件
    Maven 常用配置
    U盘装win7系统
    eval json ajax
    Maven--pom.xml 配置详解
    Maven 构建
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568545.html
Copyright © 2020-2023  润新知