2014-09-18 2 views
0

ListFragment가 있고 클래스 파일에서 데이터베이스 데이터를 검색하여 JSON으로 변환했습니다. 그것은 잘 작동하고 심지어 로그 결과와 나에게 결과를 보여 줬지만 로그 후 아무 일도 일어나지 않아, 그 후에 아무것도 표시되지 않을 것이다. 내 코드는 다음과 같습니다 :ListView가 데이터 가져 오기 및 첨부 후 업데이트되지 않음

public void loadItems(){ 
     SharedPreferences pref = getActivity().getSharedPreferences("myId", Context.MODE_PRIVATE); 
     String getId = pref.getString("int1", "no data"); 
     Uri uri = Uri.parse("content://" + getString(R.string.AUTORITY_ORDER) + "/orders"); 
     final Cursor cursor = getActivity().getContentResolver().query(uri, null, "order_id = " + getId, null, null); 
     JSONArray array = new JSONArray(); 
     if (cursor != null && cursor.getCount() > 0) { 
      cursor.moveToFirst(); 
      while(!cursor.isAfterLast()){ 
       JSONObject object = new JSONObject(); 
       try { 
        object.put("destination_address", cursor.getString(0)); 
        object.put("destination_code", cursor.getString(1)); 
        object.put("destination_email", cursor.getString(2)); 
        object.put("destination_name", cursor.getString(3)); 
        object.put("destination_phone", cursor.getString(4)); 
        object.put("_id", cursor.getString(5)); 
        object.put("order_delivered", cursor.getString(6)); 
        object.put("order_id", cursor.getString(7)); 
        object.put("order_picked", cursor.getString(8)); 
        object.put("order_type", cursor.getString(9)); 
        object.put("source_address", cursor.getString(10)); 
        object.put("source_code", cursor.getString(11)); 
        object.put("source_email", cursor.getString(12)); 
        object.put("source_name", cursor.getString(13)); 
        object.put("source_number", cursor.getString(14)); 
        object.put("source_phone", cursor.getString(15)); 
        array.put(object); 
        Log.d("ARRAYTEST", String.valueOf(array.length())); 
        cursor.moveToNext(); 
       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
      } 
      parseJsonFeed(array); 
     } 
    } 

    public void parseJsonFeed(JSONArray array){ 
     Log.d("jsonArr", array.toString()); 
     try { 

      JSONObject itemss = new JSONObject(array.toString()); 
      Log.d("DEtailCheck", itemss.toString()); 
      LinearLayout layout1, layout2; 
      layout1 = (LinearLayout) getActivity().findViewById(R.id.names1); 
      layout2 = (LinearLayout) getActivity().findViewById(R.id.names2); 
      SharedPreferences pref = getActivity().getSharedPreferences("myCode", Context.MODE_PRIVATE); 
      Editor edit = pref.edit(); 
      edit.putString("key1", itemss.getString("source_code")); 
      edit.putString("key11", itemss.getString("destination_code")); 
      edit.putString("key5", itemss.getString("order_picked")); 
      edit.commit(); 
      String sourceName, sourceAdrress, destinationName, destinationAddress; 
      sourceAdrress = itemss.getString("source_address"); 
      sourceName = itemss.getString("source_name"); 
      destinationAddress = itemss.getString("destination_address"); 
      destinationName = itemss.getString("destination_name"); 
      Log.d("ddsList", sourceName + " " + sourceAdrress + " " + destinationName + " " + destinationAddress); 
      TextView txt1 = (TextView) getActivity().findViewById(R.id.name2); 
      TextView txt2 = (TextView) getActivity().findViewById(R.id.address2); 
      TextView txt3 = (TextView) getActivity().findViewById(R.id.name1); 
      TextView txt4 = (TextView) getActivity().findViewById(R.id.address1); 

      if (sourceAdrress.isEmpty()) { 
       layout1.setVisibility(View.GONE); 
       txt1.setText(destinationName); 
       txt2.setText(destinationAddress); 
      } else if (destinationAddress.isEmpty()) { 
       layout2.setVisibility(View.GONE); 
       txt3.setText(sourceName); 
       txt4.setText(sourceAdrress); 
      } else { 
       txt1.setText(destinationName); 
       txt2.setText(destinationAddress); 
       txt3.setText(sourceName); 
       txt4.setText(sourceAdrress); 
      } 
      String check = itemss.getString("order_picked"); 
      String type = itemss.getString("order_type"); 
      Log.d("ORDER_TYPE:", type + " " + check); 
      if (type.matches("1")) { 
       Button change = (Button) getActivity().findViewById(R.id.buttonClose); 
       change.setText("Delivery"); 
      } else if (type.matches("2")) { 
       Button change = (Button) getActivity().findViewById(R.id.buttonClose); 
       change.setText("PickUp"); 
      } else if (check.matches("true") && type.matches("3")) { 
       Button change = (Button) getActivity().findViewById(R.id.buttonClose); 
       change.setText("Close Delivery"); 
      } 

     } catch (JSONException e) { 
      // TODO: handle exception 
     } 

    } 

경우 Log.d ("jsonArr"은 Array.toString());은 Nothing Happens, no error, no warning이 나오는 로그입니다.

배열이 같다 :

[{"order_delivered":"false","source_number":"540DB0FA07A1F","destination_phone":"787438743","order_id":"5","source_phone":"7347477","destination_email":"[email protected]","source_code":"963483","order_picked":"false","destination_code":"711652","destination_address":"73, Layi-Oyekanmi shhsje","source_email":"[email protected]","_id":"2","destination_name":"hjjfdj","source_name":"gshd","source_address":"Sabo, Yaba hjhgshs","order_type":"3"}] 

어떤 도움을 주시면 감사하겠습니다, 감사합니다.

답변

0

JSONException이 발생합니다.

이 같은 뭔가

// TODO: handle exception 

교체 :

Log.e("ARRAYTEST", "Error", e); 

그런 다음 응용 프로그램을 실행하고 로그를 확인합니다.

+0

오 그래, 배열을 JSONObject로 변환하지 않습니다. –

관련 문제