How to find error from LogCat in android?

跟風遠走 提交于 2019-11-28 02:19:13

问题


Method or Hint for finding error from LogCat. How to find and solve error from Logcat?


回答1:


I like this approach:

adb logcat -s System.err



回答2:


I try to explain on a very basic example of logcat output taken from different post :

12-13 12:41:57.052: W/System.err(542): org.json.JSONException: No value for TAG_CONTACTS
12-13 12:41:57.052: W/System.err(542):  at org.json.JSONObject.get(JSONObject.java:354)
12-13 12:41:57.052: W/System.err(542):  at org.json.JSONObject.getJSONArray(JSONObject.java:544)
12-13 12:41:57.052: W/System.err(542):  at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:56)
12-13 12:41:57.063: W/System.err(542):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-13 12:41:57.063: W/System.err(542):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-13 12:41:57.063: W/System.err(542):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 12:41:57.072: W/System.err(542):  at android.os.Looper.loop(Looper.java:123)
12-13 12:41:57.072: W/System.err(542):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-13 12:41:57.072: W/System.err(542):  at java.lang.reflect.Method.invokeNative(Native Method)
12-13 12:41:57.072: W/System.err(542):  at java.lang.reflect.Method.invoke(Method.java:507)
12-13 12:41:57.072: W/System.err(542):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

As you can see from first line exception is "JSONException" which heppened because of "No value for TAG_CONTACTS". From line number 4 you can see, that it happened in "AndroidJSONParsingActivity" on line 56. Now when you know what is the exception and where it happens, you should be able to solve it !




回答3:


In LogCat you will find among all those run time errors there is a tag "Caused by" under text attribute.you will click the next line of that error and that will point you to the code where that error is occurring.




回答4:


MenuBar --> Window --> Show view --> Other --> logcat Here you can find exception in red letters. and solving is based on the exception you are getting



来源:https://stackoverflow.com/questions/13857560/how-to-find-error-from-logcat-in-android

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