以下是错误日志
10-29 16:16:15.586: E/AndroidRuntime(1498): FATAL EXCEPTION: main
10-29 16:16:15.586: E/AndroidRuntime(1498): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)
10-29 16:16:15.586: E/AndroidRuntime(1498): at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:325)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:16:15.586: E/AndroidRuntime(1498): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:16:15.586: E/AndroidRuntime(1498): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.View.measure(View.java:12723)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.os.Looper.loop(Looper.java:137)
10-29 16:16:15.586: E/AndroidRuntime(1498): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-29 16:16:15.586: E/AndroidRuntime(1498): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 16:16:15.586: E/AndroidRuntime(1498): at java.lang.reflect.Method.invoke(Method.java:511)
10-29 16:16:15.586: E/AndroidRuntime(1498): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-29 16:16:15.586: E/AndroidRuntime(1498): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-29 16:16:15.586: E/AndroidRuntime(1498): at dalvik.system.NativeStart.main(Native Method)
10-29 16:21:40.772: E/AndroidRuntime(1568): FATAL EXCEPTION: main
10-29 16:21:40.772: E/AndroidRuntime(1568): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)
10-29 16:21:40.772: E/AndroidRuntime(1568): at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:325)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:21:40.772: E/AndroidRuntime(1568): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
10-29 16:21:40.772: E/AndroidRuntime(1568): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.View.measure(View.java:12723)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.os.Looper.loop(Looper.java:137)
10-29 16:21:40.772: E/AndroidRuntime(1568): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-29 16:21:40.772: E/AndroidRuntime(1568): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 16:21:40.772: E/AndroidRuntime(1568): at java.lang.reflect.Method.invoke(Method.java:511)
10-29 16:21:40.772: E/AndroidRuntime(1568): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-29 16:21:40.772: E/AndroidRuntime(1568): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-29 16:21:40.772: E/AndroidRuntime(1568): at dalvik.system.NativeStart.main(Native Method)
网上找了两天,基本定位是在XML上,但是,就是找不到具体是哪有问题。求大侠救命呐
------解决思路----------------------
楼主太长了,
ActionBarContextView can only be used with android:layout_width="match_parent"这里,你看下你的activty的主题配置。
------解决思路----------------------
源码是这样的:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
if (widthMode != MeasureSpec.EXACTLY) {
throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
"with android:layout_width=\"match_parent\" (or fill_parent)");
}
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode != MeasureSpec.AT_MOST) {
throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
"with android:layout_height=\"wrap_content\"");
}
.
.
.
有个说法:
When overriding this method, you must call View.setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by View.measure(int, int). Calling the superclass' View.onMeasure(int, int) is a valid use.
如果复写onMeasure这个方法,必须调用View.setMeasuredDimension(int, int)来保存这个view的宽度和高度,不然就会报这个错。
目前流传在网络的唯一的解答在这里:http://code.google.com/p/android/issues/detail?id=19021,这个是自定义的Dialog的theme会有这个问题,如果继承系统现有的theme,也就是指定parent为系统自带的theme,就不会出现这个问题。
你可以自己debug,解决了一定记得把方法分享一下。
------解决思路----------------------
第一层LinearLayout和RelativeLayout也没用,删掉看看。
------解决思路----------------------
尽量别用match_parent,老版本不兼容,用fill_parent就行