zoukankan      html  css  js  c++  java
  • ArrayMap java.lang.ArrayIndexOutOfBoundsException

    错误堆栈:

    java.lang.ArrayIndexOutOfBoundsException: length=0; index=1
            at android.support.v4.util.SimpleArrayMap.indexOf(SimpleArrayMap.java:83)
            at android.support.v4.util.SimpleArrayMap.put(SimpleArrayMap.java:381)
    

    示例错误代码:

    final ArrayMap testArrayMap = new ArrayMap();
    
            new  Thread("线程1"){
                @Override
                public void run() {
                    super.run();
                    while (true){
                        testArrayMap.put("aaa","fffff");
                    }
                }
    
            }.start();
    
            new  Thread("线程2"){
                @Override
                public void run() {
                    super.run();
                    while (true){
                        testArrayMap.clear();
                    }
                }
    
            }.start();
    

    错误原因:
    ArrayMap 不支持多行程,请在一个线程里面使用。不然会导致数组越界。如果想在多线程里面使用,请使用HasTable。

    google 的 ArrayMap 本身就没有支持多线程,在最新的support 包里面,如果你还多线程使用ArrayMap,就会throw CME (ConcurrentModificationException)

  • 相关阅读:
    js继承《转》
    千分位分割正则
    所有事件失效
    658. Find K Closest Elements
    278. First Bad Version
    153. Find Minimum in Rotated Sorted Array
    11. Container With Most Water
    205. Isomorphic Strings
    75. Sort Colors
    695. Max Area of Island
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568530.html
Copyright © 2011-2022 走看看