开发者社区> 问答> 正文

自定义view出错,怎么找到出错位置? 400 请求报错 

android开发使用自定义view的时候,在部分机型上会报出这样的错误:

java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
	at android.view.View.measure(View.java:18864)
	at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
	at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464)
	at android.view.View.measure(View.java:18849)
	at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
	at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
	at android.view.View.measure(View.java:18849)
	at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:2019)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at android.widget.ScrollView.onMeasure(ScrollView.java:487)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
	at android.view.View.measure(View.java:18849)
	at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:2019)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at android.widget.ScrollView.onMeasure(ScrollView.java:487)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:447)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5904)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3073)
	at android.view.View.measure(View.java:18849)
	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2343)
	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1380)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1623)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1265)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6945)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:826)
	at android.view.Choreographer.doCallbacks(Choreographer.java:605)
	at android.view.Choreographer.doFrame(Choreographer.java:575)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:812)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:145)
	at android.app.ActivityThread.main(ActivityThread.java:6837)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
应用里面使用的自定义view比较多,通过这个信息不能确定是什么地方出错了,有没有什么办法可以确定出错的位置?另外,在自动已的里面已经调用 setMeasuredDimension(int measuredWidth, int measuredHeight) 了或者super.onMeasure(widthMeasureSpec, heightMeasureSpec);了,会是什么原因造成的?求解答,谢谢!

展开
收起
kun坤 2020-05-30 15:13:15 1375 0
1 条回答
写回答
取消 提交回答
  • 从报错来说,你的确在 onMeasure中没有调用setMeasuredDimension方法,建议贴出代码看看######可能是编译的时候出的问题,重新编译过后就没有问题了

    2020-05-30 15:13:23
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
面向失败设计 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载