2014-09-27 2 views
1

기본적으로 DOM Parser를 사용하여 목록보기의 RSS 피드에서 제목, 설명, pubDate 및 축소판을 검색합니다. 여기 내 샘플 코드입니다. 처음 세 태그 썸네일이 나에게 문제를주고, 나에게 예외가 발생되어 내 parser..But 제대로 읽어스트림을 디코딩 할 수 없습니다 : fileNotFoundException

public ArrayList<HashMap<String, String>> processXML(
       InputStream inputStream) throws Exception { 
       DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory 
       .newInstance(); 
       DocumentBuilder documentBuilder = documentBuilderFactory 
       .newDocumentBuilder(); 
       Document xmlDocument = documentBuilder.parse(inputStream); 
       Element rootElement = xmlDocument.getDocumentElement(); 
       L.m("" + rootElement.getTagName()); 
       NodeList itemsList = rootElement.getElementsByTagName("item"); 
       NodeList itemChildren = null; 
       Node currentItem = null; 
       Node currentChild = null; 
       NamedNodeMap mediaThumbnailAttr = null; 
       Node currentAttribute=null; 
       int count = 0; 
       ArrayList<HashMap<String, String>> results = new ArrayList<>(); 
       HashMap<String, String> currentMap = null; 
       for (int i = 0; i < itemsList.getLength(); i++) { 
       currentItem = itemsList.item(i); 
       itemChildren = currentItem.getChildNodes(); 
       currentMap = new HashMap<>(); 
       for (int j = 0; j < itemChildren.getLength(); j++) { 
       currentChild = itemChildren.item(j); 
       if (currentChild.getNodeName().equalsIgnoreCase("title")) { 
       // L.m(currentChild.getTextContent()); 
       currentMap.put("title", currentChild.getTextContent()); 
       } 
       if (currentChild.getNodeName().equalsIgnoreCase("pubDate")) { 
       // L.m(currentChild.getTextContent()); 
       currentMap 
       .put("pubDate", currentChild.getTextContent()); 
       } 
       if (currentChild.getNodeName().equalsIgnoreCase(
       "description")) { 
       // L.m(currentChild.getTextContent()); 
       currentMap.put("description", 
       currentChild.getTextContent()); 
       } 

       if(currentChild.getNodeName().equalsIgnoreCase("media:thumbnail")){ 
        //L.m(""+currentChild.getTextContent()); 
        mediaThumbnailAttr = currentChild.getAttributes(); 
        for(int k=0;k<mediaThumbnailAttr.getLength(); 
          k++){ 
         currentAttribute = mediaThumbnailAttr.item(k); 
         if(currentAttribute.getNodeName() 
           .equalsIgnoreCase("url")){ 
          count++; 

          //L.m(currentChild.getAttributes().item(0).getTextContent()); 

         } 
         //L.m(); 
         currentMap.put("imageURL", currentChild 
       .getAttributes().item(0).getTextContent()); 
        } 
        count=0; 
       } 
       } 
       if (currentMap != null && !currentMap.isEmpty()) { 
       results.add(currentMap); 
       } 
       count = 0; 
       } 
       return results; 
       } 
       } 
     } 

...

 Unable to decode stream: java.io.FileNotFoundException: 
      /http:/i.dailymail.co.uk/i/pix/2014/09/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG: open failed: ENOENT (No such file or directory). 

은 setImageURI에 문제가 있습니까 (Uri.parse (currentItem.get ("imageURL"))));

+0

내가 알 수있는 한 가지 : URL 시작 부분에 "/"가 추가되었습니다. 'http://i.dailymail.co.uk/i/pix/2014/09/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG'여야합니다. "/http://i.dailymail.co.uk/i/pix/2014/09/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG" –

+0

알아. holder.articleImage.setImageURI (Uri.parse (currentItem.get ("imageURL"))); 내 어댑터의 getView 메서드 내부에 예외가 표시되지 않지만 다시 이미지가 목록에 표시되지 않습니다 .. – Theo

+0

맞다.하지만 잘못된 URL이 표시됩니다. 그것을 확인하십시오. 테스트 목적으로 하드 코딩 된 URL을 시도해 볼 수 있습니다 :'holder.articleImage.setImageURI (Uri.parse ("http : /i.dailymail.co.uk/i/pix/2014/09/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG")) ; 그리고 이미지가 표시되는지 확인하십시오. @ 테오 –

답변

1

오류 :

Unable to decode stream: java.io.FileNotFoundException: 
     /http:/i.dailymail.co.uk/i/pix/2014/09/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG: open failed: ENOENT (No such file or directory). 

이 (가) "/"URL이 시작되기 전에를 참조하십시오. 이로 인해 FileNotFoundException이 발생했습니다. 먼저 응답에서 올바른 URL을 얻었는지 확인하십시오.

그리고 테스트를 위해

, 하드 코드 된 URL로 시도 :

holder.articleImage.setImageURI(Uri.parse("http:/i.dailymail.co.uk/i/pix/2014/0‌​9/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG")); 

나는 그것이 잘 작동합니다 같아요. 따라서 응답을 바로 잡으십시오. 그러면 좋은 결과를 얻으실 수 있습니다.

+0

Lm (currentChild.getAttributes(). 항목 (0) .getTextContent())을 주석 처리하면; if (currentChild.getNodeName(). equalsIgnoreCase ("media : thumbnail")) {} 안에있는 이미지를 로그 파일에서 읽습니다.이 부분은 괜찮습니다. Uri.parse() 안에 이미지 이미지의 링크를 넣었습니다. 그러나 나에게 보여 줬지만 아직 행운은 없었습니다. – Theo

+0

그 오류가 있습니까? 또는 이미지가 표시되지 않습니까? –

+0

이미지가 표시되지 않습니다. 또한 예외 ..... 오류 비트 맵 URL에서 resolveUri이 실패했습니다. http : /i.dailymail.co.uk/i/pix/2014/0 ?? 9/27/1411832985119_Puff_Image_galleryImage_SUNDERLAND_ENGLAND_SEPTEM.JPG – Theo

1

예. 당신이 옳았!!! 난 .. 이미지를 다운로드하는

public class ImageDownloader extends AsyncTask<String, String, Bitmap> { 

    private MyAdapter parentActivity; 


    public ImageDownloader(MyAdapter parentActivity) { 
    super(); 

    this.parentActivity = parentActivity; 
} 

    protected Bitmap doInBackground(String... args) { 
    try { 
     Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent()); 
     return bitmap; 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 

    protected void onPostExecute(Bitmap image) { 
    if(image != null){ 
     parentActivity.updateBitmap(image); 

    } 
    } 
} 

을 별도의 AsyncTask를을 만들 수 있었다 또한

new ImageDownloader(MyAdapter.this).execute(currentItem.get("imageURL")); 

은 이미지를 얻고 목록에 표시합니다. 당신의 아이디어에 감사드립니다. 그들은 나를 많이 도와 줬어 !!

관련 문제