Sign in to follow this  
Andy474

[C#, XML] NullReferenceException

Recommended Posts

i'm following Tutorials from this site :http://nickgravelyn.com/archive/#tileengine: and im Currently on Tutorial 13: Currently we are building a 'Preprocessor' for a custom xml file and when reading it in I place this code;
[ContentProcessor(DisplayName = "Tile Layer Processor")]
    public class TileLayerProcessor : ContentProcessor<XmlDocument, TileLayerContent>
    {
        public override TileLayerContent Process(
            XmlDocument input, ContentProcessorContext context)
        {
            TileLayerContent layer = new TileLayerContent();

            foreach (XmlNode node in input.DocumentElement.ChildNodes) <-- Line 21
            {
                if (node.Name == "Textures")
                {
                    foreach (XmlNode textureNode in node.ChildNodes)
                    {
                        string file = textureNode.Attributes["File"].Value;
                        int index = int.Parse(textureNode.Attributes["UUID"].Value);



The Following Error Message is Tripped on Line 21 when I build (i think) The Error Message
Error	1	Building content threw NullReferenceException: Object reference not set to an instance of an object.
   at TileContent.TileLayerProcessor.Process(XmlDocument input, ContentProcessorContext context) in I:\2D_Games\TileGame(1)\TileContent\Tiles\TileLayerProcessor.cs:line 22
   at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
   at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, 
String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& 
dependencyTimestamps, KeyValuePair`2[]& warnings)	I:\2D_Games\TileGame(1)\TileGame(1)\Content\Layers\Layer3.layer	TileGame(1)





I am not the most familiar person with xml, however i cannot figure out wether this error message IS in the .layer file (which is a custom extension). or whether it is in the TileLayerProcessorClass(Listed Above) Any help on this error is Appreciated, Is it a problem in the XML file?(below) or the class? once again this problem doesnt pickup in his tutorial code. just in mine.
the Custom XML file

<TileLayer>
  
  <Textures>
    <Texture File="Tiles\se_free_grass_texture.jpg" UUID="0" />
    <Texture File="Tiles\se_free_road_texture.jpg" UUID="1" />
    <Texture File="Tiles\se_free_rock_texture.jpg" UUID="2" />
    <Texture File="Tiles\se_free_mud_texture.jpg" UUID="3" />
  </Textures>

  <Properties>
    <Alpha>1.0</Alpha>    
  </Properties>

  <Layout Width="50" Height="50">
      Some really massive array of [0,1,2,3]'s which is 50x50
  </Layout>
  
</TileLayer>






Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this