2016-06-09 38 views
0

以下是堆棧跟蹤,當我用CardView支持庫Android的 - 無法實例cardview

java.lang.NoClassDefFoundError: android/support/v7/cardview/R$color 
    at android.support.v7.widget.CardView.initialize(CardView.java:227) 
    at android.support.v7.widget.CardView.<init>(CardView.java:113) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465) 
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172) 
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105) 
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:178) 
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247) 
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) 
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861) 
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:317) 
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429) 
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548) 
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533) 
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966) 
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533) 
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$58(RenderTask.java:659) 
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:380) 
    at com.android.tools.idea.rendering.RenderTask.inflate(RenderTask.java:659) 
    at com.android.tools.idea.uibuilder.model.NlModel.inflate(NlModel.java:327) 
    at com.android.tools.idea.uibuilder.model.NlModel.updateModel(NlModel.java:373) 
    at com.android.tools.idea.uibuilder.model.NlModel$1.run(NlModel.java:237) 
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:333) 
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:323) 
    at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:267) 
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:282) 
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234) 
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) 
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:378) 
    at com.intellij.util.Alarm$Request.run(Alarm.java:389) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:227) 
    at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:187) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

發生這種情況時,我創建了一個CardView的線性佈局內的滾動視圖我。這是該活動的XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.user.myapplication.ListActivity"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </android.support.v7.widget.CardView> 


    </ScrollView> 



</LinearLayout> 

可以

回答

0

如果你使用eclipse有人解釋這個錯誤的原因不僅僅是導入V7緊湊庫項目到您的工作空間,並將其添加爲一個庫你的項目還有,如果你是從終端比你能做什麼做的是放android-support-v7-appcompat庫項目(您可以在sdk\extras\android\support\v7\appcompat找到)在你的項目目錄下,這行添加到您的project.properties文件

android.library.reference.1=../android-support-v7-appcompat 

不要忘記將jar文件v4,v7添加到您的項目中。

+0

support.v7.appcompat已經存在於我的外部庫以及項目文件夾中..除此之外,我的build.gradle文件也支持support.v7-appcompat和support.v7.cardview-23.4。 0 –

+0

@AirirhSrivastav在添加依賴項後嘗試清理並重新構建項目。 –

+0

我已經做了那些...那就是爲什麼我問 –

相關問題