2014-01-15 45 views
0

我知道這個問題有很多解決方案,但我仍然面臨一個錯誤。我有一個字符串數組,通過webservice插入到數組的數據。 以下是我的代碼。如何在android中按字母順序排序字符串數組?

protected void onPostExecute(String result) { 
      dialog.dismiss(); 
      int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
        (float) 1, getResources().getDisplayMetrics()); 

      JSONArray jarray; 

      try { 
       jarray= new JSONArray(result); 
        name= new String[jarray.length()]; 
for (int i=0;i<jarray.length();i++){ 

        JSONObject jobj = jarray.getJSONObject(i); 
       name[i]= jobj.getString("Name"); 
} 

現在在名字[我]我得到的名字,但這些不是按字母順序排列。我試過Arrays.sort(名字);但它給了我空指針。 enter image description here

+0

空指針後logcat –

+0

使用arrayList,你可以很容易地排序 –

+1

如果答案是可行的比請接受它,它會幫助他人,而他們將有相同類型的問題。 –

回答

相關問題