Jump to content
  • Advertisement
Sign in to follow this  
Andy474

[C#, XML] NullReferenceException

This topic is 3283 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Solved :) i forget to acctually load the File :P so was trying to pass through a blank file everytime.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!