2014-10-28 57 views
26

我試圖RecyclerView和CardView添加到我的項目RecyclerView ClassNotFound的

dependencies { 
compile 'com.android.support:appcompat-v7:21.0.0' 
compile 'com.android.support:support-v13:21.0.0' 
compile 'com.android.support:cardview-v7:21.0.0' 
compile 'com.android.support:recyclerview-v7:21.0.0' 
compile 'com.viewpagerindicator:library:[email protected]' 
compile project(':facebook') 
} 

它編譯,但我得到的異常以下時,對設備

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.RecyclerView" on path: DexPathList[[zip file "/data/app/xxxx.apk"],nativeLibraryDirectories=[/data/app-lib/xxxx, /vendor/lib, /system/lib]] 
     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 
     at android.view.LayoutInflater.createView(LayoutInflater.java:559) 
     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652) 

回答

58

佈局問題。更改

<RecyclerView 
    ... 

<android.support.v7.widget.RecyclerView 
    ... 

如果編程創建RecyclerView - 確保你有適當的進口:

import android.support.v7.widget.RecyclerView; 
+0

是啊,看起來像我使用最新的buildtools,它確實有android.view.RecyclerView,所以在android studio中沒有錯誤,但我在4.4.4設備上運行它... – 2014-10-28 09:31:57

+0

在我的佈局中,我寫過,仍然面臨同樣的問題。在CS類中,我能夠找到android.support.v7.widget,但不是android.support.v7.widget.RecyclerView – 2016-03-22 12:53:02

-2

這是一個建設問題,運行它。 ..

是的在少數情況下,該代碼以前工作,突然它 停止工作(應用程序啓動時崩潰p)當我同步並構建了一個 舊版本的代碼。

修復方法是關閉並重新啓動Eclipse並清理項目 並清理所有依賴庫項目。然後它再次正確地開始工作 。

在刷新 項目文件時,這是Eclipse中的某種構建問題。

更新:特別是,如果您不小心修改了 「.classpath」文件(要恢復到較舊版本),Eclipse/Android SDK 可能會感到困惑,並且無法正確構建項目。當您重新啓動 Eclipse並清理項目時,Eclipse將重新修改「.classpath」 文件並正確構建。

+0

如果你要提供來自另一個相關問題的答案,請鏈接http:/ /stackoverflow.com/a/20421764而不是複製+粘貼。 – tir38 2015-06-11 22:04:28

0

這爲我工作:

compile 'com.android.support:support-v4:21.0.3' 
compile 'com.android.support:appcompat-v7:21.0.0' 
compile 'com.android.support:recyclerview-v7:+' 
compile 'com.android.support:cardview-v7:+' 

最好的問候!

+0

順便說一下,Android Studio中的渲染有一些isssues http://code.google.com/p/ android/issues/detail?id = 72117 http://code.google.com/p/android/issues/detail?id=85118,在我的情況下,版本1.1.0 a沒有預覽recyclerview – lgallard 2015-04-15 15:06:10

0

在eclipse中,您需要從其他直接或間接導入的庫中清除其他(舊版本)的android-support-v4.jar。

我的實例;我的項目(TurkRenkleri)包括MobilePlayGround,其中包括appcompat庫(它有一個較舊版本的支持v4 jar)。所以我沒有得到下面給出的錯誤,而是我有RecyclerView ClassNotFound。

做完this後,我終於得到了下面的錯誤,並明白了問題所在解決辦法(刪除舊罐子)。

[2015-04-29 00:59:53 - TurkRenkleri] Found 2 versions of android-support-v4.jar in the dependency list, 
[2015-04-29 00:59:53 - TurkRenkleri] but not all the versions are identical (check is based on SHA-1 only at this time). 
[2015-04-29 00:59:53 - TurkRenkleri] All versions of the libraries must be the same at this time. 
[2015-04-29 00:59:53 - TurkRenkleri] Versions found are: 
[2015-04-29 00:59:53 - TurkRenkleri] Path: E:\calisma alani\oyunlar\android-support-v7-appcompat\libs\android-support-v4.jar 
[2015-04-29 00:59:53 - TurkRenkleri] Length: 621451 
[2015-04-29 00:59:53 - TurkRenkleri] SHA-1: 5896b0a4e377ac4242eb2bc785220c1c4fc052f4 
[2015-04-29 00:59:53 - TurkRenkleri] Path: E:\calisma alani\oyunlar\RecyclerView\libs\android-support-v4.jar 
[2015-04-29 00:59:53 - TurkRenkleri] Length: 1157388 
[2015-04-29 00:59:53 - TurkRenkleri] SHA-1: 605c447c20ca216b5556af9f215af5d4bba1b117 
[2015-04-29 00:59:53 - TurkRenkleri] Jar mismatch! Fix your dependencies 
3

我做了所有在這篇文章中所說的話,但沒有任何工作。

對我而言有什麼作用:

1.在你的構建中添加這個。gradle這個:

compile 'com.android.support:support-v4:21.0.3' 
compile 'com.android.support:appcompat-v7:21.0.0' 
compile 'com.android.support:recyclerview-v7:+' 
compile 'com.android.support:cardview-v7:+' 

2.增加了RecyclerView作爲STANDAR查看和指示類:

<view 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="android.support.v7.widget.RecyclerView" 
    android:id="@+id/my_recycler_view" 
    /> 

3.Then增加進口:

import android.support.v7.widget.RecyclerView; 

希望這有助於!

+0

我有被遺忘的回收站是它自己的編譯系。不需要做其他的事情。 – 2015-09-07 21:39:05

0

確保爲編制 'com.android.support:recyclerview-v7:22.2.0'

0

這爲我工作。加入這個APP的gradle這個

compile 'com.android.support:design:23.1.1' 
在佈局

<android.support.v7.widget.RecyclerView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/recyclerView" 
    android:layout_centerVertical="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

,並在您的活動

import android.support.v7.widget.RecyclerView; 

和內部

那麼你的onCreate

RecyclerView recyclerView;