在Android library中不能使用switch-case語句訪問資源ID的原因分析及解決方案

來源:互聯網
上載者:User

標籤:ace   back   聲明   theme   r.java   必須   原因   java   car   


報錯是因為case分支後面跟的參數必須是常數,也就是說library中的R.java的資源ID不是常數,
public static final class animator {
public static int design_appbar_state_list_animator = 0x7f020001;
}
public static final class array {
public static int card_tabList = 0x7f030001;
}
public static final class attr {
public static int actionBarDivider = 0x7f040001;
public static int actionBarItemBackground = 0x7f040002;
public static int actionBarPopupTheme = 0x7f040003;
...}

如上面所示每一個資源ID都沒有被聲明為final
項目下的R.java的資源ID如下
public static final class animator {
public static final int design_appbar_state_list_animator=0x7f020000;
}
public static final class array {
public static final int card_tabList=0x7f030000;
public static final int tab_list=0x7f030001;
}

查了很多資料,除了用if-else替換沒有其他解決方案[Facepalm]

  

在Android library中不能使用switch-case語句訪問資源ID的原因分析及解決方案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.