字符串数组保存到Map使用避免超出范围崩溃

买了个新手机,应用又崩溃了,连上电脑看catlog,报错:java.lang.ArrayIndexOutOfBoundsException。

java 复制代码
 String APV[] = new String[] {
            "",
            "Android 1.0 , BASE, 200809",
            "Android 1.1 , BASE_1_1, 200902",
            "Android 1.5 , CUPCAKE, 200904",
            "Android 1.6 , DONUT, 200909",
            "Android 2.0 , ECLAIR, 200910",
            "Android 2.0.1 , ECLAIR_0_1, 200912",
            "Android 2.1.X , ECLAIR MR1, 201001",
            "Android 2.2.x , FROYO, 201005",
            "Android 2.3 / 2.3.1 / 2.3.2, GINGERBREAD, 201012",
            "Android 2.3.3 / 2.3.4 , GINGERBREAD MR1, 201102",
            "Android 3.0.X , HONEYCOMB, 201102",
            "Android 3.1.X , HONEYCOMB MR1, 201105",
            "Android 3.2 , HONEYCOMB MR2, 201107",
            "Android 4.0 / 4.0.1 / 4.0.2, ICE CREAM SANDWICH, 201110",
            "Android 4.0.3 / 4.0.4, ICE CREAM SANDWICH MR1, 201112",
            "Android 4.1 / 4.1.1, JELLY BEAN, 201207",
            "Android 4.2 / 4.2.2, JELLY BEAN MR1, 201211",
            "Android 4.3, JELLY BEAN MR2, 201307",
            "Android 4.4, KITKAT, 201310",
            "Android 4.4W, KITKAT_WATCH, 201406",
            "Android 5.0, Lollipop , 201411",
            "Android 5.1, Lollipop MR1, 201503",
            "Android 6.0, Marshmallow, 201510",
            "Android 7.0, Nougat, 201608",
            "Android 7.1.1, Nougat, 201610",
            "Android 8.0, Oreo, 201708",
            "Android 8.1, Oreo MR1, 201712",
            "Android 9.0, Pie, 201808",
            "Android 10.0, Q, 201909",
            "Android 11, Red Velvet Cake, 20200909",
            "Android 12, Snow Cone, 20211005"
};

String s = APV[android.os.Build.VERSION.SDK_INT]; 
复制代码
android.os.Build.VERSION.SDK_INT,3年多前的旧手机=31,新手机=36,超过范围直接崩溃。

使用Map取不到值="null",不会崩溃。

java 复制代码
HashMap<Integer, String> map_APV;

map_APV = new HashMap<>();
for (int i=0; i<APV.length; i++) {
    map_APV.put(i, APV[i]);
}

String s = map_APV.get(android.os.Build.VERSION.SDK_INT);
相关推荐
恋猫de小郭19 分钟前
KotlinLLM 开源 ,一个可以在运行时自己生成永久 Kotlin 代码的 Agent 库
android·前端·人工智能
游戏开发爱好者827 分钟前
iOS应用加固方案全解析:源码加固与IPA在线加固对比
android·macos·ios·小程序·uni-app·cocoa·iphone
大鹏说大话1 小时前
PHP 异步处理方案:队列使用场景与 RabbitMQ 实操
android
molihuan1 小时前
最新 Paddle-Lite Android平台编译
android·ocr·paddle·推理·端侧·paddle lite
小肝一下2 小时前
多态(上)
android·开发语言·c++·vscode·多态·面向对象·伊蕾娜
三少爷的鞋2 小时前
Android 面试系列:Retrofit 的 suspend 是如何实现的?
android
solo_9914 小时前
用 LSPosed 模拟录屏音频编码器卡顿:从思路到落地
android
zzq779714 小时前
别把大模型 API Key 写进 APK:移动 AI 应用接口防盗刷实践
android·人工智能·安全·app加固·御盾安全·安卓加固
xiaopang16 小时前
RK3568 AOSP 编译与快速部署实战
android