如何解决:IllegalStateException:Config为null,请确保你的init(config)方法调用super.init(config)

时间:2012-06-25 09:17:23

标签: java exception liferay portlet liferay-6

我正在开发一个MVCPortlet。我在view.jsp中有一个链接,它在liferay中调用portlet类中的方法。

<portlet:actionURL var="listComplexURL" name="listComplex"/>    
<a href="<%=listComplexURL%>">Comlex</a>
This is the <b>Refahi</b> portlet.

这是portlet类中的相应方法:

public void listComplex(ActionRequest actionRequest, ActionResponse actionResponse)
    throws SQLException, ClassNotFoundException
{
    RFH_Complex rfh_complex = new RFH_Complex();
    ArrayList<Complex> complexList = rfh_complex.getComplexList();
    actionRequest.setAttribute("complexList", complexList);
    actionResponse.setRenderParameter("jspPage", "/complex.jsp");
}

我部署了portlet并单击了链接,但是我收到以下错误:

  

java.lang.IllegalStateException:Config为null,请确保你的init(config)&gt;方法调用super.init(config)

即使我实现init()方法并在其中调用super.init(),我仍然会收到此错误。

这是我的getComplexList()方法:

public ArrayList<Complex> getComplexList() throws ClassNotFoundException, SQLException
{
    ArrayList<Complex> complexList = new ArrayList<Complex>();
    ResultSet rs = dbOperation.executeQuery("SELECT * FROM rfh_complex");
    while(rs.next())
    {
        Complex complex = new Complex(rs.getInt("PKComplexID"), rs.getString("ComplexName"), 
                rs.getString("ComplexCity"), rs.getInt("IsActive"));
        complexList.add(complex);
    }
    return complexList;
}

Complex.jsp包含以下代码行:

ArrayList<Complex> complexList = (ArrayList)actionRequest.getAttribute("complexList");

1 个答案:

答案 0 :(得分:1)

listComplex的方法签名错误。它应该只抛出IOException和PortletException。您应该在方法体或其他地方处理SQLException和ClassNotFoundException(我尝试我的控制器永远不会抛出SQLException)。在您的情况下,无需重写init方法。