title: XmlPullAttributes cannot be cast to XmlBlockParser
body: <p><a href="https://stackoverflow.com/questions/33293644/custom-xml-file-to-view/33293734#33293734">Custom xml file to view</a></p>
  
  <p>This is an error produced from the above question</p>
  
  <p>I managed to get the XML file saved into the assets folder, and loaded (and I can even navigate through the different parts of the parser and produce outputs from them) but when I try to pass the <code>XmlPullParser</code> to <code>LayoutInflater</code> I get the above error. I am not totally sure why it is happening though.</p>
  
  <p>Below is the activity that I am using (the part of it that involves parsing the Xml file) as well as the xml file (called activity_main.sv) and the logcat.</p>
  
  <p>Ignore the file extension of the xml file. I simply renamed it because the IDE was having fits about inclusion. If the xml file is saved in the res/layouts folder it works just fine (I know because I copied it directly out of the res/layouts folder).</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState){
  ...
       try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            XmlPullParser parser = factory.newPullParser();
            InputStream in = getResources().getAssets().open("views/activity_main.sv");
            parser.setInput(new InputStreamReader(in));
            LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  //        The below line is line 73, the line which is giving me issue
            View view = inflate.inflate(parser, null);
            setContentView(view);
       }catch(Exception e){
            e.printStackTrace();
  //        Consider the below line Log.d("TAG","Well fuck me it didnt work"). AppLog is a custom class I created to help manage logging.
            AppLog.log("Well fuck me it didnt work");
       }
  }
  </code></pre>
  
  <p>And my basic relativelayout saved as "activity_main.sv"</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;
  
      &lt;TextView android:text="@string/hello_world" android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And finally the logcat output</p>
  
  <pre><code>10-24 19:36:55.273: W/EGL_emulation(4724): eglSurfaceAttrib not implemented
  10-24 19:36:55.273: W/OpenGLRenderer(4724): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa34192a0, error=EGL_SUCCESS
  10-24 19:47:15.252: W/System.err(8074): java.lang.ClassCastException: android.util.XmlPullAttributes cannot be cast to 
  
  android.content.res.XmlBlock$Parser
  10-24 19:47:15.253: W/System.err(8074):     at android.content.res.Resources$Theme.obtainStyledAttributes
  
  (Resources.java:1483)
  10-24 19:47:15.253: W/System.err(8074):     at android.content.Context.obtainStyledAttributes(Context.java:460)
  10-24 19:47:15.253: W/System.err(8074):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
  10-24 19:47:15.253: W/System.err(8074):     at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
  10-24 19:47:15.253: W/System.err(8074):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
  10-24 19:47:15.253: W/System.err(8074):     at pro.bladebeat.intentplayground.MainActivity.onCreate
  
  (MainActivity.java:73)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.Activity.performCreate(Activity.java:5933)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.Instrumentation.callActivityOnCreate
  
  (Instrumentation.java:1105)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.ActivityThread.performLaunchActivity
  
  (ActivityThread.java:2251)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.ActivityThread.handleLaunchActivity
  
  (ActivityThread.java:2360)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
  10-24 19:47:15.253: W/System.err(8074):     at android.os.Handler.dispatchMessage(Handler.java:102)
  10-24 19:47:15.253: W/System.err(8074):     at android.os.Looper.loop(Looper.java:135)
  10-24 19:47:15.253: W/System.err(8074):     at android.app.ActivityThread.main(ActivityThread.java:5221)
  10-24 19:47:15.253: W/System.err(8074):     at java.lang.reflect.Method.invoke(Native Method)
  10-24 19:47:15.253: W/System.err(8074):     at java.lang.reflect.Method.invoke(Method.java:372)
  10-24 19:47:15.253: W/System.err(8074):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
  
  (ZygoteInit.java:899)
  10-24 19:47:15.253: W/System.err(8074):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  10-24 19:47:15.257: D/AppLog(8074): Well fuck me it didnt work
  </code></pre>
  
  <p>EDIT
  After adding the factory.setValidating(true) statement. I have a different error now.</p>
  
  <pre><code>11-04 14:59:52.682: W/System.err(4664): org.xmlpull.v1.XmlPullParserException: unsupported feature: http://xmlpull.org/v1/doc/features.html#validation (position:START_DOCUMENT null@1:1) 
  11-04 14:59:52.684: W/System.err(4664):     at org.kxml2.io.KXmlParser.setFeature(KXmlParser.java:2100)
  11-04 14:59:52.684: W/System.err(4664):     at org.xmlpull.v1.XmlPullParserFactory.newPullParser(XmlPullParserFactory.java:135)
  11-04 14:59:52.684: W/System.err(4664):     at pro.bladebeat.intentplayground.MainActivity.onCreate(MainActivity.java:36)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.Activity.performCreate(Activity.java:5933)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
  11-04 14:59:52.684: W/System.err(4664):     at android.os.Handler.dispatchMessage(Handler.java:102)
  11-04 14:59:52.684: W/System.err(4664):     at android.os.Looper.loop(Looper.java:135)
  11-04 14:59:52.684: W/System.err(4664):     at android.app.ActivityThread.main(ActivityThread.java:5221)
  11-04 14:59:52.684: W/System.err(4664):     at java.lang.reflect.Method.invoke(Native Method)
  11-04 14:59:52.684: W/System.err(4664):     at java.lang.reflect.Method.invoke(Method.java:372)
  11-04 14:59:52.684: W/System.err(4664):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  11-04 14:59:52.684: W/System.err(4664):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>