gpt4 book ai didi

android - GridLayout 出错,应用程序崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:48 25 4
gpt4 key购买 nike

我对布局还很陌生,但我能够成功地制作出非常漂亮的布局(适用于平板电脑)。在 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 中使用它。

关于android - GridLayout 出错,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7943214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com