Tencent/matrix · error · XmlPullParserException
Unexpected start tag: found
Error message
Unexpected start tag: found ${parser.getName()}, expected ${firstElementName} What it means
PowerProfile's XML parser throws XmlPullParserException("Unexpected start tag: found X, expected Y") when the document's first element name does not match the expected firstElementName. It validates the root element so subsequent parsing assumptions hold, mirroring AOSP's PowerProfile implementation.
Solutions
- Make the XML root element match the expected name expected by the constructor (check the firstElementName argument you passed).
- Pass the correct firstElementName to PowerProfile to match your document's root tag.
- Use the library's bundled/default power-profile resource rather than a custom file unless intentionally overriding.
Example fix
// before new PowerProfile(parser, "device"); // XML root is <powerprofile> // after new PowerProfile(parser, "powerprofile"); // matches XML root element
Defensive patterns
Strategy: validation
Validate before calling
XmlPullParser p = res.getXml(R.xml.power_profile);
int t;
while ((t = p.next()) != XmlPullParser.START_TAG && t != XmlPullParser.END_DOCUMENT) {}
if (t == XmlPullParser.START_TAG && !"powerprofile".equals(p.getName())) {
// wrong root tag: fix XML or pass matching firstElementName
} Try / catch
try {
PowerProfile profile = new PowerProfile(parser, firstElementName);
} catch (XmlPullParserException e) {
MatrixLog.e(TAG, "bad power profile XML: " + e.getMessage());
} Prevention
- Match the constructor's firstElementName argument to the XML root element.
- Copy power-profile XML from a matching Android version/source tree.
- Never point the parser at unrelated XML resources.
When it happens
Trigger: Passing an XML whose root element is not the expected name (e.g. a generic <resources> or <device> root when "powerprofile" is expected) into the PowerProfile constructor.
Common situations: Using a power-profile XML copied from the wrong Android version with a renamed root; hand-written test fixtures with a mismatched root tag; pointing the parser at an arbitrary XML resource instead of a power profile.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- No start tag found
- TaskExecuteException wrapping e.getMessage()
- failure to skip type, cannot find type def of typeid:
- Matrix init, Matrix should not be null.
- you must init Matrix sdk first
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/264578ae0df83c32.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/PowerProfile.java:665
public double getBatteryCapacity() {
return getAveragePower(POWER_BATTERY_CAPACITY);
}
@SuppressWarnings("StatementWithEmptyBody")
static class XmlUtils {
public static void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException {
int type;
while ((type = parser.next()) != parser.START_TAG
&& type != parser.END_DOCUMENT) {
}
if (type != parser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
if (!parser.getName().equals(firstElementName)) {
throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
", expected " + firstElementName);
}
}
public static void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException {
int type;
while ((type = parser.next()) != parser.START_TAG
&& type != parser.END_DOCUMENT) {
}
}
}
}View on GitHub (pinned to 3b8293bd65)