2015-05-18 368 views
1

我想從onPostexecute方法獲得onNewIntent方法中的意圖後,顯示AlertBuild對話框。 routeList [1,9,13]。目前,我得到這個錯誤java.lang.ArrayStoreException: source[0] of type java.lang.Integer cannot be stored in destination array of type java.lang.CharSequence[]類型java.lang.Integer的source [0]不能存儲在java.lang.CharSequence類型的目標數組中[]

ArrayList<Integer> routeList = extras 
       .getIntegerArrayList("stop_route"); //[1,9,13] 
     int routeListSize = routeList.size(); 
     if(routeListSize > 0){ 

     CharSequence charSequence[] = routeList 
       .toArray(new CharSequence[routeList.size()]); 
     for (int i = 0, size = routeList.size(); i < size; i++) { 
      charSequence[i] = String.valueOf(routeList.get(i)); 
     } 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 

     builder.setTitle("Select"); 

       builder.setMultiChoiceItems(charSequence, null, 
      new DialogInterface.OnMultiChoiceClickListener() { 

     @Override 
     public void onClick(DialogInterface dialog, int which, 
         boolean isChecked) { 
        // TODO Auto-generated method stub 

       } 
      }); 
    } 

回答

5

試圖改變自己的for像這樣:的

String[] charSequence = new String[routeList.size()]; 
     for (int i = 0, i<routeList.size(); i++) { 
      charSequence[i] = String.valueOf(routeList.get(i)); 
     } 

代替:

CharSequence charSequence[] = routeList 
       .toArray(new CharSequence[routeList.size()]); 
     for (int i = 0, size = routeList.size(); i < size; i++) { 
      charSequence[i] = String.valueOf(routeList.get(i)); 
     } 
相關問題