Android:載入CardView,RecyclerView異常解決方案

來源:互聯網
上載者:User

標籤:

  今天下午,在自己的項目中添加了對RecyclerView的支援,但是一直報出“Caused by: java.lang.NoClassDefFound

Error: android.support.v7.recyclerview.R$styleable”的異常,在網上搜羅了一遭,稀裡糊塗一下午仍沒有解決問題,最後自己嘗試從最初載入類庫入手找問題,結果最終找到的原因都讓自己萌生了想把自己殺了的念頭。

  下面從頭一一說起:

  首先,建議大家在使用Google的Android Support Library時,不要採用直接將..\sdk\extras\android\m2repository

\com\android\support\recyclerview-v7中的xx.aar檔案複製到libs目錄,添加Build Path這種方式,還是匯入Android 代碼最官方;不知道如何匯入的筆者參見Google官方連結:http://developer.android.com/tools/support-library/setup.html#libs-with-res。

  其次,對於載入CardView,RecyclerView時報出的異常一種是android-support-v4.jar這個包版本不匹配,另一種就是在導完Android Support Library後,點擊滑鼠右鍵——Properties——Android——勾選Is Library——點擊Apply。記住一定要點擊Apply,應用當前改變,否則配置失效。我就是在導完RecyclerView包後,沒點擊Apply,結果一直報出上述紅色標註的異常,困擾了我一下午。

  最後將完整的導包實踐羅列一下,方便大家查閱。  

    • Select File > Import.
    • Select Existing Android Code Into Workspace and click Next.
    • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding theappcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
    • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both theandroid-support-v4.jar and android-support-v7-appcompat.jar files.
    • Right-click the library project folder and select Properties > check Is Library>click Apply.
    • Click OK to complete the changes.

 

Android:載入CardView,RecyclerView異常解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.