Why Android Studio finds error in XmlResourceParser

235 Views Asked by At

Simple code for parsing activity_main.xml

XmlResourceParser xmlResourceParser = res.getXml(R.layout.activity_main);

Android Studio finds error "Expected resource of type xml", but runs this code and app works correct. enter image description here

2

There are 2 best solutions below

0
Francesco Bonnì On

Android Studio uses an inspector to help you find an error, it expects a resource type 'R.xml.nameresource', obviously works because steps still an xml. For delete error you can disable inspection 'Constant and Resource Type Mismatches' options or add a xml folder in your res folder, create a new xml file and copy your content

0
JasonWyatt On

The resource type of that resource is technically not xml, instead it is actually layout. I think it must still be working because layout files are also XML files.