因为你在插入元素之前没有对araylist赋chu初值,在元素为空的情况下是不允许引用该元素的,如果改成这样就可以了.
ArrayList al = new ArrayList();
al.Add("test0");
al.Add("test1");
al.Add("test2");
al.Insert(1,"mytest");

解决方案 »

  1.   

    如果是
    al.Insert(2,"mytest");
    al.Insert(4,"test");
    仍出错,WHY?
      

  2.   

    Insert(index,object)中的index参数必须在al的范围内,songlian(雨) 的代码只有4项,Insert的参数index不能超过3(索引从0开始)
      

  3.   

    问题是,如果我刚初始化ArrayList al = new ArrayList();只时al范围是多少?我是不是只能用add()或用insert时index要按0,1,2,...这样排?
      

  4.   

    按你意思,你可以用hashtable来实现。
      

  5.   

    Insert的全意是Insert Before例如al有三项 "0","1","2"那么Insert(index,"a")中,index的范围是0,1,2,3 (0到al.Length)插入的位置是:0     1     2     3
    ↓    ↓    ↓    ↓
      "0" , "1" , "2"