How to read Android LogCat - Android

被刻印的时光 ゝ 提交于 2020-01-11 14:24:30

问题


I have an error in my Logcat that causes my app to crash but I have no idea how to tell what line the error is on or what the error exactly is, here is my LogCat hopefully someone can tell me what the problem is.

    07-16 15:37:49.255: E/AndroidRuntime(21545): FATAL EXCEPTION: main
07-16 15:37:49.255: E/AndroidRuntime(21545): java.lang.NullPointerException
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.ListView.measureScrapChild(ListView.java:1163)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1294)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.ListView.onMeasure(ListView.java:1155)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:579)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:392)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at com.navdrawer.SimpleSideDrawer.onMeasure(SimpleSideDrawer.java:443)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2162)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.View.measure(View.java:13011)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1091)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.os.Looper.loop(Looper.java:154)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at android.app.ActivityThread.main(ActivityThread.java:4945)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at java.lang.reflect.Method.invokeNative(Native Method)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at java.lang.reflect.Method.invoke(Method.java:511)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-16 15:37:49.255: E/AndroidRuntime(21545):    at dalvik.system.NativeStart.main(Native Method)

回答1:


I always look in the log cat from top to down and am looking for the first line that says at MYCLASS this is the last spot that the error occurred. In your case this would be:

07-16 15:37:49.255: E/AndroidRuntime(21545):    at com.navdrawer.SimpleSideDrawer.onMeasure(SimpleSideDrawer.java:443)

From here you can select that line (in eclipse) and eclipse will take you right to the problem line in code. Now look back at the top of your log cat and you will see you have a nullpointerexception. If you can't detect what is wrong immediately, you can set a break point on that line of code and debug your code. Once you hit that breakpoint look at each item that is on that line and find something that is null.

Without seeing your code, I can't help you to say what is null in this case.

I hope this helps.



来源:https://stackoverflow.com/questions/17685619/how-to-read-android-logcat-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!