2017-02-21 3 views
3

J'essaye de lire un fichier XML dessinable à partir d'un fichier jar dans mon projet android.XmlPullParserException fonction non prise en charge

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; 
    } 

Cette méthode permet de trouver le fichier, lu à l'intérieur du texte. Toutefois, il jette l'exception ci-dessous, quand il est le réglage des entrées:

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

Il est vraiment bizarre parce que le fichier xml ne contient pas de texte comme celui-ci: http://xmlpull.org/v1/doc/features.html#validation

Ceci est le fichier xml qui est situé dans le pot

<?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> 

Répondre

5

le problème que vous faites face n'est pas lié au contenu du fichier XML que vous validez. Au lieu de cela, la ligne XmlPullParserFactory.setValidating(true) semble être la cause de l'exception que vous obtenez. Ce que fait cette ligne est de configurer l'analyseur créé pour valider le fichier XML. Malheureusement, l'implémentation de l'analyseur créée par XmlPullParserFactory.newPullParser() ne semble pas prendre en charge la validation. Commenter la ligne factory.setValidating(true) dans votre code devrait résoudre le problème.