从logcat

时间:2016-11-11 15:46:34

标签: android android-studio logcat

是否赞扬从logcat获取更长的错误跟踪?例如,我在下面得到错误跟踪,但显然它不足以指出问题所在:

  

E / AndroidRuntime:FATAL EXCEPTION:main进程:com.site.pkg,PID:   10527 android.view.InflateException:二进制XML文件行#6:二进制   XML文件行#6:错误膨胀类片段       在android.view.LayoutInflater.inflate(LayoutInflater.java:551)       在android.view.LayoutInflater.inflate(LayoutInflater.java:429)       at com.site.pkg.MainActivity $ Adapter.onCreateViewHolder(MainActivity.java:62)       在com.site.pkg.MainActivity $ Adapter.onCreateViewHolder(MainActivity.java:53)       在android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:5833)       在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5057)       在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:4967)       在android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:2029)       在android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)       在android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)       在android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)       在android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)       在android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2843)       在android.view.View.measure(View.java:20171)       在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:716)       在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)       在android.view.View.measure(View.java:20171)       在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)       在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)       在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)       在android.view.View.measure(View.java:20171)       在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)       在android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:389)       在android.view.View.measure(View.java:20171)       在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)       在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)       在android.view.View.measure(View.java:20171)       在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)       在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)       在android.widget.LinearLayout.measureVertical(LinearLayout.java:747)       在android.widget.LinearLayout.onMeasure(LinearLayout.java:629)       在android.view.View.measure(View.java:20171)       在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6328)       在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)       在com.android.internal.policy.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:3143)       在android.view.View.measure(View.java:20171)       在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2644)       在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1599)       在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1891)       在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1487)       在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:7450)       在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:920)       在android.view.Choreographer.doCallbacks(Choreographer.java:695)       在android.view.Choreographer.doFrame(Choreographer.java:631)       在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:906)       在android.os.Handler.handleCallback(Handler.java:739)       在android.os.Handler.dispatchMessage(Handler.java:95)       在android.os.Looper.loop(Looper.java:158)       在android.app.ActivityThread.main(ActivityThread.java:7237)       at java.lang.reflect.Method.invoke(Native Method)       在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230)       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)引起:android.view.InflateException:二进制XML文件行#6:   膨胀类片段时出错       在android.vie

1 个答案:

答案 0 :(得分:0)

根据经验,你可以从上到下阅读,直到你发现一个你认识的类是你的,而不是在android内部。

在堆栈跟踪中,您可以找到此行

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.site.pkg, PID: 10527 
android.view.InflateException: Binary XML file line #6: Binary XML file 
line #6: Error inflating class fragment at 
android.view.LayoutInflater.inflate(LayoutInflater.java:551) at 
android.view.LayoutInflater.inflate(LayoutInflater.java:429) at 
com.site.pkg.MainActivity$Adapter.onCreateViewHolder(MainActivity.java:62) 
at

其中有趣的部分是MainActivity$Adapter.onCreateViewHolder(MainActivity.java:62)

因此,您应该在MainActivity.java 62行开始调查。

但在您的情况下,您遇到此错误Error inflating class fragment at android.view.LayoutInflater.inflate(LayoutInflater.java:551)。 很可能在您试图膨胀的片段布局中出现了问题。

因此,请检查您的布局xml文件,查找错误,也许您正在尝试添加一个已损坏或不存在的自定义窗口小部件(当然只是猜测)。

希望我至少指出了正确的方向。