搜不狗

记录学习工作点滴

java.util.ConcurrentModification Exception总结

| Comments

初探

Exception描述

今天又一次发现这个bug,印象原来有发生过这个问题,但是当时没有细细总结现在又发生了。这次就好好总结下,深入理解其中的原理。

  java.util.ConcurrentModificationException
        at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
        at com.linshi.www.linshi.Me.seller.ItemsListAdapter$1.success(ItemsListAdapter.java:63)
        at com.linshi.www.linshi.Me.seller.ItemsListAdapter$1.success(ItemsListAdapter.java:59)
        at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5111)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
        at dalvik.system.NativeStart.main(Native Method)

代码示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    Callback<ItemMessage> deleteCallback = new Callback<ItemMessage>() {
        @Override
        public void success(ItemMessage item, Response response) {
          //wrong 
          //This foreach loop creates an Iterator object in the background.
          for(ItemMessage i:itemMessages){
             if(i.getItemId() == currentItemId){
                 itemMessages.remove(i);
             }
          }

          //Right
          for(int i = 0; i<itemMessages.size(); i++){
              if(itemMessages.get(i).getItemId() == currentItemId){
                  itemMessages.remove(i);
              }
          }


         //wrong
         ListIterator<ItemMessage> itWrong = itemMessages.iterator();
         while(itWrong.hasNext()){
          ItemMessage value = itWrong.next();
           if(value.getItemId() == currentItemId){
               itemMessages.remove(value);
           }
         }

         //right
         ListIterator<ItemMessage> it = itemMessages.listIterator();
         while (it.hasNext()){
          ItemMessage value = it.next();
          if(value.getItemId() == currentItemId){
              it.remove();// This wil remove the element that we just got using the next() method
              it.add(new ItemMessage());// THis inserts the element immediately before the next call to next()
          }
      }

      adapter.notifyDataSetChanged();
      }
      @Override
      public void failure(RetrofitError error) {
          //handle the error
      }
  }

美帝B1/B2旅游商务10年签总结

| Comments

由于一直非常向往去美帝走走,特别是一直看了高晓松的《晓说》和《晓松奇谈》被洗脑。感觉美帝的制度值得去亲身体验下,另外个人也是做IT的对硅谷特别向往。

必备材料:

  1. D160确认信
  2. 预约确认信
  3. 护照照片(1张,5cmX5cm)
  4. 护照

D160表格

表格是在线填写:https://ceac.state.gov/genniv/ 这个表格非常关键,要求填写很多个人信息。填的时候可以用鼠标悬停提示,有中文可选。这里有一份中文的填写指南,可以帮助。

这个表格填的时候30分钟会自动登出,所以填一半记得保存下。然后填表的时候要上传一个照片,白底,2X2寸正方形的照片。 小林同学帮我在家照的,但是最后还是不行,因为眼睛反光了。然后在大使馆里面用5欧的自动照相机照的。

据说这个表格系统会自动识别分析,基本过不过应该这个表就有答案。我猜是会给签字官一个置信区间的建议吧,哈哈。