0
我在嘗試調試Resources$NotFoundException
時遇到了一些問題。我試圖從一個枚舉項添加到動態一AlertDialog
:無法調試ResourceNotFoundException
下面是從我Activity
代碼:
final ArrayList<CharSequence> lstChoices = new ArrayList<CharSequence>();
for (TrendingManager.Filter fltFilter : TrendingManager.Filter.values()) {
lstChoices
.add(getResources()
.getString(
getApplicationContext()
.getResources()
.getIdentifier(
fltFilter.name().toLowerCase(),
"string",
getApplicationContext()
.getApplicationInfo().packageName)));
}
這裏的枚舉列表:
public class TrendingManager {
public static enum Filter {
ONLY_PRIVATE, ONLY_PUBLIC, ONLY_HQ, ONLY_LQ
};
}
我有所有這些在我的strings.xml
定義4枚枚舉,它適用於我的手機,但我從用戶的手機收到崩潰報告,其中說:
android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:260)
at android.content.res.Resources.getString(Resources.java:344)
at com.mridang.myapp.Trend.onOptionsItemSelected(Trend.java:230)
at android.app.Activity.onMenuItemSelected(Activity.java:2564)
...
...
...
我真的失去了爲什麼發生這種情況。有關爲什麼找不到資源的任何想法?
在我的模擬器或手機上本地運行代碼不會引發異常。 –
你應該在你的問題中寫下這個。你是否檢查過包中包含'strings.xml'? – Kai
它似乎是。我使用了我上傳到Play商店的APK,並運行APKTool進行反編譯。我在其中找到了'strings.xml',這些字符串存在於文件中。我在我的手機上安裝了該APK,甚至工作得很好。 –