{"record":{"id":"f1de96f75736a43e","repo":"iBotPeaches/Apktool","slug":"could-not-initialize-parser","errorCode":null,"errorMessage":"Could not initialize parser.","messagePattern":"Could not initialize parser\\.","errorType":"exception","errorClass":"XmlPullParserException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java","lineNumber":124,"sourceCode":"    public void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException {\n        if (inputEncoding != null) {\n            throw new XmlPullParserException(NOT_SUPPORTED);\n        }\n\n        reset();\n        mIn = new BinaryDataInputStream(new BufferedInputStream(inputStream));\n        mParser = new ResChunkPullParser(mIn);\n        try {\n            if (!nextChunk()) {\n                throw new IOException(\"Input file is empty.\");\n            }\n            if (mParser.chunkType() != ResChunkHeader.RES_XML_TYPE) {\n                throw new IOException(\"Unexpected chunk: \" + mParser.chunkName() + \" (expected: RES_XML_TYPE)\");\n            }\n        } catch (IOException ex) {\n            mIn = null;\n            mParser = null;\n            throw new XmlPullParserException(\"Could not initialize parser.\", this, ex);\n        }\n\n        mParser = new ResChunkPullParser(mIn, mParser.dataSize());\n    }\n\n    @Override\n    public String getInputEncoding() {\n        return null;\n    }\n\n    @Override\n    public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException {\n        throw new XmlPullParserException(NOT_SUPPORTED);\n    }\n\n    @Override\n    public int getNamespaceCount(int depth) {\n        return mNamespaces.getCount(depth);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java#L106-L142","documentation":"Wrapper exception: setInput() converts any IOException raised during initial AXML chunk reading (empty input [30], wrong first chunk [31], stream failure) into a standard XmlPullParserException with this message, resetting parser state. The real cause is attached as the chained exception.","triggerScenarios":"Any of the conditions in [30]/[31], or a low-level read failure on the InputStream during initialization — e.g. stream already closed, network stream dropped.","commonSituations":"Callers using the XmlPullParser API generically see this instead of the raw IOException; typical roots are empty/corrupt AXML files or non-AXML input routed to the binary parser.","solutions":["Unwrap the cause: `ex.getCause()` reveals 'Input file is empty.' or 'Unexpected chunk: ...' — follow the fix for [30] or [31].","Validate the AXML magic bytes (0x0003) and non-zero size before calling setInput.","Ensure the InputStream is open and positioned at 0 (not reused after a prior read).","Re-obtain the APK/file if the cause indicates truncation."],"exampleFix":"try {\n    parser.setInput(in, null);\n} catch (XmlPullParserException e) {\n    Throwable root = e.getCause();\n    log.error(\"AXML init failed: {}\", root != null ? root.getMessage() : e.getMessage());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (inputStream == null) throw new IllegalArgumentException(\"null stream\");\nif (file != null && file.length() < 8) throw new IllegalArgumentException(\"AXML too small\");","typeGuard":null,"tryCatchPattern":"try {\n    parser.setInput(in, null);\n} catch (XmlPullParserException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof IOException) {\n        // empty input, wrong chunk type, or stream failure — see [30]/[31]\n    }\n}","preventionTips":["Always inspect the chained cause of XmlPullParserException from setInput.","Pre-validate magic and size before initializing the parser."],"tags":["apktool","axml","xml-pull-parser","parsing"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}