2017-02-21 5 views
3

내 안드로이드 프로젝트의 jar 파일에서 drawable xml 파일을 읽으려고합니다.XmlPullParserException 지원되지 않는 기능

private Drawable readDrawableFromJar(String p_strFilePath) { 
     InputStream stream = getClass().getClassLoader().getResourceAsStream(p_strFilePath); 
     XmlPullParser parser = null; 
     try { 
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); 
      factory.setValidating(true); 
      factory.setNamespaceAware(true); 
      parser = factory.newPullParser(); 
      parser.setInput(stream, "UTF-8"); 
     } catch (XmlPullParserException e) { 
      Log.e(LOG_TAG, "there is something for " + p_strFilePath + " " + e); 
     } 


     Drawable drawable = null; 
     try { 
      if (parser != null) { 
       drawable = VectorDrawableCompat.createFromXml(getContext().getResources(), parser); 

       return drawable ; 
      } else { 
       Log.e(LOG_TAG, "parser is null for " + p_strFilePath); 
      } 

     } catch (XmlPullParserException e) { 
      Log.e(LOG_TAG, "there is something for " + p_strFilePath + " " + e); 
     } catch (IOException e) { 
      Log.e(LOG_TAG, "there is something for " + p_strFilePath + " " + e); 
     } 
     return null; 
    } 

이 방법은 파일 내부에서 텍스트를 읽을 수 있습니다. 이 입력을 설정하는 것입니다 그러나, 그것은 아래의 예외가 발생합니다 :

org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#validation (position:START_DOCUMENT [email protected]:1) 

XML 파일과 같은 텍스트가 포함되어 있지 않기 때문에 정말 이상 해요 : http://xmlpull.org/v1/doc/features.html#validation

이있는 XML 파일입니다 항아리 안에

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:viewportWidth="24" 
    android:viewportHeight="24" 
    android:width="24dp" 
    android:height="24dp"> 
    <path 
     android:pathData="M12 3C7.031 3 3 7.027 3 12.001 3 16.967 7.031 21 12 21 16.971 21 20.999 16.967 20.999 12.001 20.998 7.027 16.971 3 12 3m0 20C5.925 23 1 18.073 1 12.001 1 5.925 5.925 1 12 1 18.077 1 23 5.925 23 12.001 22.998 18.073 18.076 23 12 23" 
     android:fillColor="#242838" /> 
    <path 
     android:pathData="M13 18h-2v-7h2z" 
     android:fillColor="#242838" /> 
    <path 
     android:pathData="M10 10h3v2h-3z" 
     android:fillColor="#242838" /> 
    <path 
     android:pathData="M10 16h4v2h-4z" 
     android:fillColor="#242838" /> 
    <path 
     android:pathData="M11 6h2v2h-2z" 
     android:fillColor="#242838" /> 
</vector> 

답변

5

당신이 직면 한 문제는 유효성을 검사하는 xml 파일의 내용과 관련이 없습니다. 대신 XmlPullParserFactory.setValidating(true) 줄이 예외의 원인 인 것 같습니다. 이 줄이하는 일은 xml의 유효성을 검사하기 위해 생성 된 파서를 구성하는 것입니다. 아쉽게도 XmlPullParserFactory.newPullParser()에 의해 생성 된 파서 구현은 유효성 검사를 지원하지 않습니다. 코드에 factory.setValidating(true) 행에 주석을 달아 문제를 해결해야합니다.