android – GridLayout给出错误,崩溃应用程序
作者:互联网
我对布局很新,但我能够成功地制作一个非常好看的布局(对于平板电脑).在Eclipse中,它运行良好.我在Android 4.0(ICS)上使用’目标’完成了所有操作,但显然我的平板电脑只运行3.0(Honeycomb).当我意识到错误时,我将查看器/编辑配置更改为3.2,但Eclipse甚至不再显示布局的图形,它只是吐出:
com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- GridLayout (Change to android.widget.GridLayout, Fix Build Path, Edit XML)
弹出错误日志:
java.lang.ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:84)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:702)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:86)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at android.view.LayoutInflater.inflate(LayoutInflater.java:367)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1317)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1071)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ConfigListener.onConfigurationChange(GraphicalEditorPart.java:493)
at com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.onRenderingTargetChange(ConfigurationComposite.java:2192)
at com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.access$4(ConfigurationComposite.java:2157)
at com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite$2.widgetSelected(ConfigurationComposite.java:441)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3783)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1398)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1383)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1195)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3629)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3284)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#4CBB17"
android:baselineAligned="false" android:weightSum="5"
>
<GridLayout
android:id="@+id/gridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:columnCount="1"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5" >
<GridLayout
android:id="@+id/gridLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#4CBB17"
android:columnCount="7" >
<Space
android:layout_width="100dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<Space
android:layout_width="117dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_gravity="fill_horizontal"
android:layout_row="0" />
<Space
android:layout_width="100dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<Space
android:layout_width="100dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<Space
android:layout_width="101dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<Space
android:layout_width="2225dp"
android:layout_height="1dp"
android:layout_column="4"
android:layout_gravity="fill_horizontal"
android:layout_row="0" />
<Space
android:layout_width="1dp"
android:layout_height="32dp"
android:layout_column="0"
android:layout_gravity="fill_horizontal"
android:layout_row="0" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_column="2"
android:layout_gravity="left"
android:layout_row="1"
android:src="@drawable/back_small" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_column="3"
android:layout_gravity="left"
android:layout_row="1"
android:src="@drawable/back_small" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_column="4"
android:layout_gravity="left"
android:layout_row="1"
android:src="@drawable/back_small" />
<ImageButton
android:id="@+id/imageView2"
android:layout_column="1"
android:layout_gravity="left"
android:layout_row="1"
android:src="@drawable/back_small" />
</GridLayout>
<GridLayout
android:id="@+id/gridLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4CBB17"
android:columnCount="9" >
<Space
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<Space
android:layout_width="100dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal"
android:layout_row="1" />
<Space
android:layout_width="100dp"
android:layout_height="15dp"
android:layout_gravity="fill_horizontal" />
<ImageButton
android:id="@+id/imageView1"
android:layout_column="8"
android:layout_gravity="left"
android:layout_row="1"
android:src="@drawable/back" />
<Button
android:id="@+id/nextButton"
android:layout_column="2"
android:layout_gravity="left"
android:layout_row="1"
android:text="Next" />
</GridLayout>
<GridLayout
android:id="@+id/gridLayout5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2" >
<LinearLayout
android:id="@+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="207dp"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/blackButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blackbutton" android:layout_weight="1"/>
<Button
android:id="@+id/redButton"
android:layout_width="match_parent"
android:layout_height="202dp"
android:layout_weight="1"
android:background="@drawable/redbutton" />
</LinearLayout>
</GridLayout>
</LinearLayout>
</GridLayout>
</LinearLayout>
最终,我可以在我的平板电脑上安装该应用程序,但它只是立即从LogCat崩溃:
10-29 23:44:05.180: E/AndroidRuntime(14135): FATAL EXCEPTION: main
10-29 23:44:05.180: E/AndroidRuntime(14135): java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.ajwest.irishpoker/ca.ajwest.irishpoker.IrishPokerActivity}: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1741)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1757)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.os.Looper.loop(Looper.java:126)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread.main(ActivityThread.java:4002)
10-29 23:44:05.180: E/AndroidRuntime(14135): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 23:44:05.180: E/AndroidRuntime(14135): at java.lang.reflect.Method.invoke(Method.java:491)
10-29 23:44:05.180: E/AndroidRuntime(14135): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
10-29 23:44:05.180: E/AndroidRuntime(14135): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10-29 23:44:05.180: E/AndroidRuntime(14135): at dalvik.system.NativeStart.main(Native Method)
10-29 23:44:05.180: E/AndroidRuntime(14135): Caused by: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.widget.AdapterView.addView(AdapterView.java:459)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.view.LayoutInflater.rInflate(LayoutInflater.java:728)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
10-29 23:44:05.180: E/AndroidRuntime(14135): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:247)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.Activity.setContentView(Activity.java:1771)
10-29 23:44:05.180: E/AndroidRuntime(14135): at ca.ajwest.irishpoker.IrishPokerActivity.onCreate(IrishPokerActivity.java:30)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
10-29 23:44:05.180: E/AndroidRuntime(14135): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1705)
10-29 23:44:05.180: E/AndroidRuntime(14135): ... 11 more
将选择2.3重新制作整个布局修复此问题?太傻了……
解决方法:
GridLayout是在Android 4.0中引入的.你不能在3.0或3.2中使用它.
标签:grid-layout,android,layout-inflater,android-layout,eclipse 来源: https://codeday.me/bug/20190726/1541256.html