내 Binary Search Tree
을 실행하려고하는데 내 주 프로그램에서 유형이 Employee
인 개체를 만들려고하는데 문제가되지 않는 것 같지만 내 BST
에서 항목을 검색하도록 선택하면, 프로그램이 종료됩니다. 프로그램이 종료되면이진 검색 트리, 검색 방법
System.out.println("Searching the Binary Search Tree");
System.out.println("Enter surname to search for:");
String choice2 = sc.nextLine();
BinaryNode a = temp.search(choice2);
Employee newEmp = (Employee) a.obj;
if (a == null)
{
System.out.println("Not Found");
}
else
{
System.out.println(newEmp.getData());
}
break;
}
, 그것은 주어진 라인
Employee newEmp = (Employee) a.obj;
하고 오류를 가리키는이 제발 일어나는 이유 java.lang.NullPointerException: null
는 사람이 말해 수있다?
'temp.search (choice2);는'null'을 반환하기 때문에? –
검색 방법을 보여 줬는데 괜찮습니까? – user1928374