【发布时间】:2020-05-03 04:13:21
【问题描述】:
我正在尝试制作一个模拟 NFA 的程序,我有状态对象和一个 NFA 对象(命名机器)。状态对象现在引用其他状态(如树数据结构但没有层次结构),NFA 对象仅定义起始状态,其余的从那里链接。
当我尝试将 NFA(命名机器)的启动状态分配给搜索变量(类型 State)时,问题就出现了。当我稍后尝试使用此对象移出 NFA 时,它会给出一个空指针错误。调试时(由打印语句显示),分配变量似乎工作正常但更奇怪:当我稍后打印对象时,它会同时打印内存引用和空值。
System.out.println(machine.getStart()); //prints out State@6bc7c054
search = machine.getStart(); //assigns the starting state of the NFA to search variable
System.out.println(search); //prints out State@6bc7c054
... (there is no code related to search variable in this chunk)
System.out.println(search + " last ref");//prints State@6bc7c054 last ref (and also)
null last ref
search = search.move(sym);//line that gives NullPointerException
非常感谢您对这里出了什么问题的任何想法
【问题讨论】: