给出android.support.v7.widget.GridLayout错误的Eclipse无法实例化

时间:2012-05-27 12:28:32

标签: android android-layout grid-layout

我试图从支持库中加入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>

当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$2.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$1.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$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.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)

基于没有人遇到此问题的事实,我怀疑我没有正确设置v7库。我遵循的步骤:

  1. 在“gridlayout”目录中创建一个库项目
  2. 将此项目添加到我的主项目
  3. 将gridlayout lib目录中的jar添加到我的主项目的lib目录中
  4. 非常感谢任何帮助。

4 个答案:

答案 0 :(得分:6)

将兼容性库更新为版本8,然后按照“extras \ android \ compatibility \ v7 \ gridlayout”文件夹中的README.txt文件中的说明进行操作。

希望这对你有所帮助。

注意:您必须使用grid:columnCount =“6”而不是android.support.v7.widget.columnCount =“6”,因为您在xmlns中声明了前缀“grid”:grid =“http:// schemas。 android.com/apk/res-auto”。

答案 1 :(得分:3)

  1. 更新eclipse,adt(甚至是版本20预览2),sdk管理器和支持库。

  2. 尝试重新启动eclipse,看看是否有帮助。

  3. 尝试创建一个全新的项目(低sdk用于min和target sdk,但不用于project.properties文件中指定的项目)并在可视化编辑器中拖动gridLayout。这将自动添加所需的库。

  4. 如果没有任何帮助,请尝试以下示例:http://code.google.com/p/android-playground/source/checkout

答案 2 :(得分:0)

我尝试了不同贡献者提供的一些解决方案(例如重启Eclipse,删除和添加libary等)

看了这个site之后,我做了以下几点:

  1. 用android-sdk替换所有库android-support-v4.jar(希望它是最新的副本)
  2. 我在xml中评论了Gridlayout,并使用布局编辑器拖动gridlayout。
  3. 之后一切都适合我。我不确定哪个步骤可以修复它,但尝试没有任何伤害。

答案 3 :(得分:0)

看来你正在为Android L做,但无论如何都包括这一行 在styles.xml中。

filter: { user: Model.name }