Reputation: 3200
I am trying to read a drawable xml file from a jar file in my android project.
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;
}
This method can find the file, read inside of the text. However, It throws the below exception, when it is setting the inputs :
org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#validation (position:START_DOCUMENT null@1:1)
It's really weird because the xml file does not contain any text like this: http://xmlpull.org/v1/doc/features.html#validation
This is the xml file that is located in the jar
<?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>
Upvotes: 3
Views: 729
Reputation: 76
The problem you face is not related to the content of the xml file you are validating. Instead, XmlPullParserFactory.setValidating(true)
line seems to be the cause of the exception you get. What this line does is to configure the parser created to validate the xml. Unfortunately, the parser implementation created by XmlPullParserFactory.newPullParser()
does not seem to support validation. Commenting the line factory.setValidating(true)
in your code should solve the problem.
Upvotes: 5