如果我写这样的代码:关于产品的try catch语句
Document d = searcher.doc(docId);
d.get("latitude")
我得到
unreported exception ... must be caught or declared to be thrown
如果我写这篇文章,
try {
Document d = searcher.doc(docId);
}
d.get("latitude")
我显然得到:
cannot find symbol
symbol : variable d
如果我写这篇文章
Document d;
try {
d = searcher.doc(docId);
}
d.get("latitude");
我得到这个:
variable d might not have been initialized
因为我不想try/catch语句扩展到所有的文件我怎么能解决这个问题呢?
感谢
如果catch语句本身不会抛出异常,则d可能为空 – Adi 2011-03-29 22:45:00
我知道,那么我们将会有NPE,它显示不正确的应用程序状态 – smas 2011-03-29 22:58:18