Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';System.NullReferenceException';使用模板c#_C#_List_Templates_Nullreferenceexception - Fatal编程技术网

';System.NullReferenceException';使用模板c#

';System.NullReferenceException';使用模板c#,c#,list,templates,nullreferenceexception,C#,List,Templates,Nullreferenceexception,我有一个代码,其中类状态包含一个模板。 班级单元实际上是我的T。 我试图将State类型的对象添加到我的列表中,它会给我一个错误,好像它指向null一样,即使我调试并看到它有很好的值,尤其是我所期望的值 public abstract class Searcher<T> where T : IEquatable<T> { List<State<T>> solution; public List<State<T>&g

我有一个代码,其中类状态包含一个模板。 班级单元实际上是我的T。 我试图将State类型的对象添加到我的列表中,它会给我一个错误,好像它指向null一样,即使我调试并看到它有很好的值,尤其是我所期望的值

public abstract class Searcher<T> where T : IEquatable<T>
{
    List<State<T>> solution;
    public List<State<T>> backTrace(State<T> n , ISearchable<T> searchable)
    {
        while (! ( n.getPrevious().Equals(searchable.getInitialState())))
        {
            if (n != null)
                solution.Add(n); //ERROR, NULL EXCEPTION }}

    "'System.NullReferenceException'.."
公共抽象类搜索器,其中T:IEquatable
{
列表解决方案;
公共列表回溯(状态n,可搜索)
{
而(!(n.getPrevious().Equals(searchable.getInitialState()))
{
如果(n!=null)
solution.Add(n);//错误,NULL异常}
“'System.NullReferenceException'…”
奇怪的是,它通过了if状态,但仍然不会将其添加到列表中,因为它给了我该错误。我的state类是:

public class State<T> where T : IEquatable<T>
{
    public T state;         // the state represented by a string/cell
    private State<T> cameFrom;  // the state we came from 
    public State<T> getPrevious()
    {
        return cameFrom;
    }
公共类状态,其中T:IEquatable
{
public T state;//由字符串/单元格表示的状态
私有状态来自;//我们来自的状态
公共状态getPrevious()
{
归来;
}

有什么帮助吗?

那么
解决方案
是在哪里定义的呢?这是这里唯一可以为空的东西。试试
列表解决方案=新列表();
。那么
解决方案
是在哪里定义的呢?这是这里唯一可以为空的东西。试试
列表解决方案=新列表();