eclipse 使用 SlidingDrawer 的图形布局中的 Eclpse 3.5 和 3.6 中的 ClassCastException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5089727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ClassCastException in Eclpse 3.5 and 3.6 when in Graphical Layout with a SlidingDrawer
提问by EraserheadIRL
Has anyone got the Graphical Layout working correctly in either Eclipse 3.5 or 3.6 when using a Sliding Drawer?
当使用滑动抽屉时,有没有人让图形布局在 Eclipse 3.5 或 3.6 中正常工作?
I keep getting the following error in both:
我不断收到以下错误:
error!
ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error LogThe following classes could not be found:
- SlidingDrawer
错误!
ClassCastException: com.android.layoutlib.bridge.MockView 无法转换为 android.view.ViewGroup 异常详细信息记录在窗口 > 显示视图 > 错误日志中找不到以下类:- SlidingDrawer
I get this error with my code and any example code you can find around:
我的代码和您可以找到的任何示例代码出现此错误:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#8CB69C">
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/drawerhandle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/drawerhandle"/>
</SlidingDrawer>
</FrameLayout>
When I run the app on a device it works fine without any problems so it's got to be a problem with either Android SDK 8, Eclipse 3.5 and 3.6 or my workspace, I've know idea yet. If it works fine for others then it's got to be something local.
当我在设备上运行该应用程序时,它运行良好,没有任何问题,因此它一定是 Android SDK 8、Eclipse 3.5 和 3.6 或我的工作区的问题,我已经知道了。如果它对其他人很好,那么它必须是本地的。
Here's the exception stack details:
这是异常堆栈的详细信息:
java.lang.ClassCastException: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
at android.view.LayoutInflater.rInflate(LayoutInflater.java:619)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:397)
at com.android.ide.common.rendering.LayoutLibrary.createLegacySession(LayoutLibrary.java:382)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:276)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange(Unknown Source)
at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:1067)
at org.eclipse.ui.forms.editor.FormEditor.setActivePage(FormEditor.java:607)
at com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.selectDefaultPage(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.addPages(Unknown Source)
at org.eclipse.ui.forms.editor.FormEditor.createPages(FormEditor.java:138)
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.EditorReference.getEditor(EditorReference.java:289)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2863)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2768)
at org.eclipse.ui.internal.WorkbenchPage.access(WorkbenchPage.java:2760)
at org.eclipse.ui.internal.WorkbenchPage.run(WorkbenchPage.java:2711)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2707)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2691)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2682)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:651)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:610)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:365)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:168)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:229)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:208)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:274)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(PackageExplorerActionGroup.java:373)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.open(PackageExplorerPart.java:526)
at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
at org.eclipse.jface.viewers.StructuredViewer.run(StructuredViewer.java:845)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:843)
at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1131)
at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1235)
at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:264)
at org.eclipse.jface.util.OpenStrategy.access(OpenStrategy.java:258)
at org.eclipse.jface.util.OpenStrategy.handleEvent(OpenStrategy.java:298)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
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(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench.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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
Thanks in advance!!
提前致谢!!
回答by Kamen
I got the same error but it turned out that I had mistaken the custom component class path in the XML file. So, check that SlidingDrawer class is in the same package or - better - fully qualify the class. For example, try:
我遇到了同样的错误,但结果是我弄错了 XML 文件中的自定义组件类路径。因此,请检查 SlidingDrawer 类是否在同一个包中,或者 - 更好地 - 完全限定该类。例如,尝试:
<com.some.class.path.SlidingDrawer
android:id="@+id/drawer"
<com.some.class.path.SlidingDrawer
android:id="@+id/drawer"
回答by user213493
3.2 resolve the issue, there is still a warning "The graphics preview in the layout editor may not be accurate: * Different corner sizes are not supported in Path.addRoundRect" but at the editor is completely usable.
3.2 解决问题,仍然提示“布局编辑器中的图形预览可能不准确:* Path.addRoundRect 中不支持不同的角尺寸”但在编辑器中完全可用。
回答by tony-eng
In all your xml
files, use strings as in the @string/
command. When I replaced the @string/
with a text string I got above error again.
在所有xml
文件中,使用@string/
命令中的字符串。当我用@string/
文本字符串替换时,我再次出现上述错误。
回答by GraehamF
I noobed it up and had a Button
inside of my SurfaceView
. In which case, the exception message is helpful.
我 noobed 并Button
在我的SurfaceView
. 在这种情况下,异常消息很有帮助。
android.view.*SomeView* cannot be cast to android.view.ViewGroup
making the Button
a sibling of the SurfaceView
in my layout xml file resolved this issue.
使我的布局 xml 文件中的Button
的同级SurfaceView
解决了这个问题。
回答by Norgul
You don't have the layout defined completely
您没有完全定义布局
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/handle"
android:content="@+id/content">
Notice how the android:handle="@+id/handle"
points at "handle", and android:content="@+id/content"
points at content, however, you don't have any of those in SlidingDrawer. I guess you should define something like this:
请注意android:handle="@+id/handle"
“句柄”处的android:content="@+id/content"
点和内容处的点,但是,您在 SlidingDrawer 中没有任何这些点。我想你应该定义这样的东西:
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/handle"
android:content="@+id/content">
<Button
android:id="@+id/slideButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff" >
</Button>
<LinearLayout
android:id="@+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:gravity="center"
android:orientation="vertical"
android:padding="10dip" >
</LinearLayout>
</SlidingDrawer>
回答by Bir
Yes even i got the same error and after searching for it over the net came to the conlcusion that its the Eclipse ADT plugin issue.
是的,即使我遇到了同样的错误,在网上搜索后得出的结论是它的 Eclipse ADT 插件问题。