簡體   English   中英

Android中AppCompat的Resources $ NotFoundException?

[英]Resources$NotFoundException for AppCompat in Android?

我的Android應用程序中有以下微調器:

<Spinner android:id="@+id/spnYear"
         style="@style/Widget.AppCompat.Spinner"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1" />

當我為其定義以下適配器時,一切正常:

adapterYears = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item);
spnYear.setAdapter(adapterYears);

但是當我定義以下適配器時:

adapterYears = new ArrayAdapter<Integer>(this, R.style.Widget_AppCompat_Light_DropDownItem_Spinner);
spnYear.setAdapter(adapterYears);

我收到運行時錯誤:

12-03 15:41:01.789: E/AndroidRuntime(922): FATAL EXCEPTION: main
12-03 15:41:01.789: E/AndroidRuntime(922): android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0057
12-03 15:41:01.789: E/AndroidRuntime(922):  at android.content.res.Resources.getValue(Resources.java:1010)
12-03 15:41:01.789: E/AndroidRuntime(922):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:2088)
12-03 15:41:01.789: E/AndroidRuntime(922):  at android.content.res.Resources.getLayout(Resources.java:849)

我注意到appcompat_v7項目中的資源沒有添加到我的apk文件中。

當我使用android.R.layout.simple_spinner_item並按住Ctrl鍵並將鼠標放在android.R.layout.simple_spinner_item我具有以下菜單:

在此處輸入圖片說明

但是,當我使用R.style.Widget_AppCompat_Light_DropDownItem_Spinner並按住Ctrl按鈕時,我沒有用於打開xml文件的任何菜單。

我認為問題在於將庫添加到我的項目中,但我找不到問題。

我已遵循鏈接https://developer.android.com/tools/support-library/setup.html#add-library,但問題仍未解決。

我現在應該怎么辦?

R.style.Widget_AppCompat_Light_DropDownItem_Spinner不是布局,它需要布局文件的ID,例如您使用的第一個文件或AppCompat 可用的support_simple_spinner_dropdown_item.xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM