An unhandled exception of type 'System.NullReferenceException' occurred

  • Thread starter Thread starter old_School
  • Start date Start date
O

old_School

Guest
I'm trying to build a bunch of objects that inherit properties from a base class and set some of the values statically or prebuilt.


Error:

An unhandled exception of type 'System.NullReferenceException' occurred in WBG_Crafting_Core.dll

Additional information: Object reference not set to an instance of an object.


I understand what the error is saying but I dont understand why its giving me the error:


Rune recipe:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WBG_Crafting_Core.Base_Items;

namespace WBG_Crafting_Core.Recipe
{
public class Recipe_Rune_a : Base_Recipe
{
private Ingredients _Ingredients = new Ingredients();

public bool Unlocked { get; set; }

public Recipe_Rune_a()
{
Name = "Recipe Rune a";
Unlocked = false;
_Ingredients.Ingredient = "Polished Ancient Stone";
_Ingredients.Amount = 1;
Ingredients.Add(_Ingredients);
NPC_Sale = 50;
NPC_Buy = 3;
WBG_Sale = 5;
}
}
}



Base Recipe

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WBG_Crafting_Core.Base_Items;

namespace WBG_Crafting_Core
{
public class Base_Recipe
{
/// <summary>
/// Recipe Name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Ingredient + Amount
/// </summary>
public List<Ingredients> Ingredients { get; set; }
/// <summary>
/// NPC Cost Displayed In NPC Shop
/// </summary>
public long NPC_Sale { get; set; }
/// <summary>
/// Amount NPC Will give to player for item
/// </summary>
public long NPC_Buy { get; set; }
/// <summary>
/// WBG Store Cost
/// </summary>
public long WBG_Sale { get; set; }
}
}






Gives an error here:

_Ingredients.Ingredient = "Polished Ancient Stone";
_Ingredients.Amount = 1;
Ingredients.Add(_Ingredients);


Its a list of an object and I'm just adding a object to the list. so i'm a little confused.

Continue reading...
 
Back
Top