先给一些代码片段public void delete(String input)
{
LinkedStack<String> addrStack = splitStr(input);
......
}
private static LinkedStack<String> splitStr(String input)
{
LinkedStack<String> addrStack = new LinkedStack<String>(); String[] s = input.split("\\.");
for (int i = 0; i < s.length; i++)
{
if (i != s.length - 1)
addrStack.push(s[i] + ".");
else
addrStack.push(s[i]);
} return addrStack;
}
编译都通过了,但是运行的时候有NullPointerException,调试的时候在splitStr函数的
LinkedStack<String> addrStack = new LinkedStack<String>();
出错,不知道为什么
小弟新手,恳请大家指教指教
{
LinkedStack<String> addrStack = splitStr(input);
......
}
private static LinkedStack<String> splitStr(String input)
{
LinkedStack<String> addrStack = new LinkedStack<String>(); String[] s = input.split("\\.");
for (int i = 0; i < s.length; i++)
{
if (i != s.length - 1)
addrStack.push(s[i] + ".");
else
addrStack.push(s[i]);
} return addrStack;
}
编译都通过了,但是运行的时候有NullPointerException,调试的时候在splitStr函数的
LinkedStack<String> addrStack = new LinkedStack<String>();
出错,不知道为什么
小弟新手,恳请大家指教指教
下面是LinkedStack<E>的定义public class LinkedStack<E> implements Cloneable
{
private Node<E> top; public LinkedStack()
{
top = null;
} public LinkedStack<E> clone()
{
LinkedStack<E> answer; try
{
answer = (LinkedStack<E>) super.clone();
} catch (CloneNotSupportedException e)
{
throw new RuntimeException(
"This class does not implements Cloneable");
} answer.top = Node.listCopy(top);
return answer;
} public boolean isEmpty()
{
return (top == null);
} public E peek()
{
if (top == null)
throw new EmptyStackException();
return top.getData();
} public E pop()
{
E answer; if (top == null)
throw new EmptyStackException(); answer = top.getData();
top = top.getLink();
return answer;
} public void push(E item)
{
top = new Node<E>(item, top);
} public int size()
{
return Node.listLength(top);
}
}