private DocumentCollection getcollection ()
{
try{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
DocumentCollection dc1 = db.getAllDocuments();
return dc1;
}
catch(Exception e) {
e.printStackTrace();
}
}
反正怎么试都不能通过编译。
------解决方案--------------------
如果程序在return之前就异常退出了,函数就有可能没有返回值
试试下面这个,不管是否有异常,都会返回值。
private DocumentCollection getcollection ()
{
DocumentCollection dc1 = null;
try{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
dc1 = db.getAllDocuments(); }
catch(Exception e) {
e.printStackTrace();
}
return dc1;
}
------解决方案--------------------
二楼的解答是正确的,函数肯定是错误的,你定义了返回类型DocumentCollection ,而在函数体结束前没有返回值,编译肯定会出错。