1

내 프로젝트에서 JSON (BaseAdapter를 통해)에서 표시된 데이터로 목록보기를 만들었습니다. 어댑터의 초기화에서 JSON for Progress Dialog가 표시된 AsyncTask를 초기화합니다.JSON이 Android Lollipop에서 작동하지 않습니다.

모든 안드로이드 버전에서 모든 것이 잘 작동하지만 안드로이드 롤리팝에서는 로딩이 멈추지 않습니다.

private class NewsJsonAsync extends AsyncTask<Void, Void, Boolean> { 

    private String mURLString = "http://json.com/json.json"; 
    private ProgressDialog mProgressDialog; 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 

     mProgressDialog = new ProgressDialog(mContext); 
     mProgressDialog.setMessage(mContext.getString(R.string.dialog_loading_title)); 
     mProgressDialog.setCancelable(false); 
     mProgressDialog.show(); 

    } 

    @Override 
    protected Boolean doInBackground(Void... params) { 

     Log.d("DO IN BACKGROUND", "BEFORE TRY/CATCH"); 
     try { 
      String stream = streamManager(); 
      jsonManager(stream); 

     } catch (JSONException e) { 
      e.printStackTrace(); 
      Log.d("JSON EXCEPTION HERE", e.getLocalizedMessage()); 
      return false; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      Log.d("IO EXCEPTION HERE", e.getLocalizedMessage()); 
      return false; 
     } 
     Log.d("DO IN BACKGROUND", "AFTER TRY/CATCH"); 
     return true; 
    } 

    @Override 
    protected void onPostExecute(Boolean result) { 
     // TODO Auto-generated method stub 
     super.onPostExecute(result); 
     if (result == true) { 
      notifyDataSetChanged(); 
      mProgressDialog.dismiss(); 
     } else { 
      mProgressDialog.dismiss(); 
     } 
    } 

    private String streamManager() throws IOException { 
     URL url = new URL(mURLString); 
     InputStream stream = url.openStream(); //open the data stream 
     byte[] bytes = new byte[stream.available()]; 

     String getBytes = ""; //holds the data recived for the server in their raw form 
     int countBytes; //indicator for the amount of bytes left 

     while ((countBytes = stream.read(bytes)) > -1) { //while the stream size is more then -1 (while there is still data) 
      getBytes += new String(bytes,0,countBytes); //add the data to the string 

     } 
     stream.close(); 
     return getBytes; 
    } 


    protected void jsonManager (String data) throws JSONException { 
     JSONArray jsonArray = new JSONArray(data); //call the JSON GENERAL array 

     String title = ""; 
     String subtitle = ""; 

     int size = jsonArray.length(); 

     for (int i = 0; i < size; i++) { 

      JSONObject jsonArticle = jsonArray.getJSONObject(i); 
      title = jsonArticle.getString(Enums.JSON_TITLE.getValue()); 
      subtitle = jsonArticle.getString(Enums.JSON_SUBTITLE.getValue()); 


      mArray.add(new NewsListWithDB(title, subtitle))); 
     } 

"TRY/CATCH 시작하기"에 로그가 표시되지 않습니다. 나는 그것이 내가 반복

12-10 09:38:38.991: I/art(23270): Background sticky concurrent mark sweep GC freed 263748(8MB) AllocSpace objects, 0(0B) LOS objects, 33% free, 10MB/16MB, paused 1.617ms total 107.675ms 

가 그 예술이 될 수 얻을 하나의 메시지와 함께 할 수있는 뭔가가 있다고 생각 로그 고양이는 문제의 원인에 따라? 나는 어떻게해야합니까?

+0

'ProgressDialog.show (context, title, message)'를 사용해 보셨습니까? 참조를 확인하십시오 [here] (http://developer.android.com/reference/android/app/ProgressDialog.html) – Joe3112

+0

JSON이로드되지 않거나 대화 상자에 문제가 없습니다 ... – EladB

+0

Ok 질문에 오해가 있었음에 틀림 없습니다. 문제를 더 잘 설명해 주시겠습니까? 그래서 문제는 JSON이 전혀로드되지 않는다는 것입니다. – Joe3112

답변

2

좋아, 대답을 찾고 후이 문제가 내 코드와 함께하지 않는 것, 문제는 안드로이드 5.

함께 나는 그들의 샘플 등하지만 아무것도 일하지 다운로드, JsonArray/된 JSONObject의 많은 자습서 시도 . 또한 같은 문제로 고통받는 개발자가 점점 늘어나고 있습니다.

Lena의 조언 덕분에 GSON을 다시 시험해 보았습니다. 이번에는 효과가있었습니다. 마지막으로 GSON을 사용하여 지쳤을 때 문제는 저조한 구현이었습니다.

감사합니다.

1

그래서 비슷한 문제가있었습니다. 내 응용 프로그램은 객체 데이터베이스에 json 객체를 저장합니다 (neodatis). 최근 앱을 롤리팝으로 업그레이드하면 모든 종류의 충돌이 발생합니다.

로그에서 JSONObject의 내부 데이터 구조가 HashMap에서 LinkedHashMap으로 변경된 것처럼 보입니다. 롤리팝 이전에 저장된 데이터가있는 경우 휴대 전화를 롤리팝으로 업그레이드하면 문제가 발생합니다.

관련 문제