Eclipse 报错 android.support.v7.widget.GridLayout 无法实例化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10773981/
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
Eclipse giving an error of android.support.v7.widget.GridLayout failed to instantiate
提问by Aviral
I have tried to incorporate the GridLayout from the support library, but it is not working. My target build is for API version 10. The XML code I am using is shown below:
我试图从支持库中合并 GridLayout,但它不起作用。我的目标版本是 API 版本 10。我使用的 XML 代码如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android.support.v7.widget.columnCount="6" >
<Button
android:id="@+id/button1"
android.support.v7.widget.layout_column="1"
android.support.v7.widget.layout_columnSpan="2"
android.support.v7.widget.layout_gravity="left"
android.support.v7.widget.layout_row="1"
android:text="Button" />
</android.support.v7.widget.GridLayout>
When Eclipse tries to compile this, the error given is: android.support.v7.widget.GridLayout failed to instantiate. The stack trace is:
当 Eclipse 尝试编译它时,给出的错误是:android.support.v7.widget.GridLayout 无法实例化。堆栈跟踪是:
java.lang.NoClassDefFoundError: android/support/v7/gridlayout/R$dimen
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:402)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:166)
at com.android.layoutlib.bridge.android.BridgeInflater.loadCustomView(BridgeInflater.java:205)
at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:133)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
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:1361)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1115)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:941)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:585)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
at org.eclipse.ui.part.MultiPageEditorPart.widgetSelected(MultiPageEditorPart.java:290)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
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.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2746)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1433)
at org.eclipse.swt.custom.CTabFolder.handleEvent(CTabFolder.java:257)
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:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
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:344)
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:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
Based on the fact that nobody is facing this problem, I suspect that I have not setup the v7 library correctly. The steps I have followed:
基于没有人面临这个问题的事实,我怀疑我没有正确设置 v7 库。我遵循的步骤:
- Create a library project at the "gridlayout" directory
- Added this project to my Main project
- Added the jar from the gridlayout lib directory to the lib directory of my main project
- 在“gridlayout”目录下创建一个库项目
- 将此项目添加到我的主项目中
- 将gridlayout lib目录下的jar添加到我主项目的lib目录下
Any help will be much appreciated.
任何帮助都感激不尽。
回答by Tri Bui
Update your Compatibility Library to revision 8, then follow the instruction in README.txt file in "extras\android\compatibility\v7\gridlayout" folder.
将您的兼容性库更新到修订版 8,然后按照“extras\android\compatibility\v7\gridlayout”文件夹中的 README.txt 文件中的说明进行操作。
Hope this help you.
希望这对你有帮助。
Notes: You must use grid:columnCount="6" instead of android.support.v7.widget.columnCount="6" because you declare the prefix "grid" in xmlns:grid="http://schemas.android.com/apk/res-auto".
注意:您必须使用 grid:columnCount="6" 而不是 android.support.v7.widget.columnCount="6" 因为您在 xmlns:grid="http://schemas.android.com 中声明了前缀 "grid" /apk/res-auto”。
回答by android developer
update eclipse, adt (even to version 20 preview 2) , sdk manager and the support library .
try to restart eclipse and see if that helps.
try to create a totally new project (with low sdk being used for the min and target sdk , but not for the one specified on the project.properties file ) and drag the gridLayout in the visual editor. this will automatically add the needed library.
if nothing helps , try this example : http://code.google.com/p/android-playground/source/checkout
更新 eclipse、adt(甚至到版本 20 预览版 2)、sdk 管理器和支持库。
尝试重新启动 eclipse,看看是否有帮助。
尝试创建一个全新的项目(低 sdk 用于 min 和目标 sdk ,但不用于 project.properties 文件中指定的项目)并在可视化编辑器中拖动 gridLayout 。这将自动添加所需的库。
如果没有任何帮助,请尝试以下示例:http: //code.google.com/p/android-playground/source/checkout
回答by Lee Yi Hong
I try a number of solution provided by different contributor (eg restart Eclipse, removing and adding libary etc)
我尝试了许多不同贡献者提供的解决方案(例如重新启动 Eclipse、删除和添加库等)
After looking at this site, I did the following:
看了这个网站后,我做了以下事情:
- Replace all the library android-support-v4.jar with the android-sdk (hoping that it will be the latest copy)
- I commented the Gridlayout in xml and use the layout editor just drag gridlayout.
- 将所有库 android-support-v4.jar 替换为 android-sdk(希望它是最新的副本)
- 我在xml中评论了Gridlayout并使用布局编辑器只需拖动gridlayout。
After that everything works for me. I am not sure which step is the one that fix it but there is no harm trying.
在那之后,一切都对我有用。我不确定哪一步是修复它的步骤,但尝试没有坏处。
回答by Mridul Shrivastava
It seems you are doing for Android L but anyway include this line inside your styles.xml.
看起来你是为 Android L 做的,但无论如何在你的 style.xml 中包含这一行。
<item name="windowActionBar">false</item>