为什么我得到com.vaadin.event.ListenerMethod$MethodException



我的小型数据库(DERBY)应用程序有一个大问题。当我点击按钮时,我得到了这样一个错误:

2011-12-25 04:21:38 com.vaadin.Application terminalError
SEVERE: Terminal error:
com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.NullPointerException
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:532)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
    at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
    at com.vaadin.ui.Button.fireClick(Button.java:550)
    at com.vaadin.ui.Button.changeVariables(Button.java:217)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1445)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1393)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1312)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
    at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
    at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.example.expert_system.Knowledge.insertPhone(Knowledge.java:280)
    at com.example.expert_system.Knowledge.buttonClick(Knowledge.java:262)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:512)
    ... 27 more

我得到这个只有当我试图从类Database_engine调用方法。

Database_engine.java:

private static String dbURL = "jdbc:derby://localhost:1527/Knowledge;create=true;user=erni;password=2ngxc3";
private static String tableName = "ERNI.PHONE";
private static Connection conn = null;
private static Statement stmt = null;


private void createConnection()
{
    try
    {
        Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
        //Get a connection
        conn = DriverManager.getConnection(dbURL); 
    }
    catch (Exception except)
    {
        except.printStackTrace();
    }
}

public void insertPhone(String producer, String model, String construction, String display_size, String system)
{
    createConnection();
    try
    {
        stmt = conn.createStatement();
        stmt.execute("insert into " + tableName + "("producer","model", "construction","dispaly_size","system") values (" + producer + "','" + model + "','" + construction + "','" + display_size + "','" + system +"')");
        stmt.close();
        //INSERT INTO ERNI.PHONE ("producer", "model", "construction", "display_size", "system") VALUES ('placek', 'na', 'oleju', 'mama ', 'krzyczy');
    }
    catch (SQLException sqlExcept)
    {
        sqlExcept.printStackTrace();
        //System.err.println("Exception: "+sqlExcept.getMessage());
    } finally {
        closeConnection();
    }
}

private void closeConnection()
{
    try
    {
        if (stmt != null)
        {
            stmt.close();
        }
        if (conn != null)
        {
            DriverManager.getConnection(dbURL + ";shutdown=true");
            conn.close();
        }           
    }
    catch (SQLException sqlExcept)
    {
    }
}

和表单方法的代码:

public void buttonClick(ClickEvent event) {
        Button source = event.getButton();
      //  
       if (source == button_2) {

            insertPhone();
            getWindow().showNotification("Open " + producerBox.getValue().toString() +" "+ 
                     model.getValue().toString()+" "+ 
                     constructionBox.getValue().toString()+" "+ 
                     displayBox.getValue().toString()+" "+ 
                     systemBox.getValue().toString());
            setReadOnly(true);  
            getWindow().showNotification(systemBox.getInputPrompt());
        } else if (source == button_1) {
            discard();
            setReadOnly(true);
            getWindow().showNotification("clear executed");
        }
    }
    private void insertPhone() {
        Database_engine addPhone = new Database_engine();
        addPhone.insertPhone(producerBox.getValue().toString(), 
                             model.getValue().toString(), 
                             constructionBox.getValue().toString(), 
                             displayBox.getValue().toString(), 
                             systemBox.getValue().toString());
    }
    private void discard() {
        producerBox.setValue(null);
        model.setValue("");
        constructionBox.setValue(null);
        displayBox.setValue(null);
        systemBox.setValue(null);
        otherColSelect.setValue(null);
        comColSelect.setValue(null);
    }

请告诉我我做错了什么。


好的,我已经检查了你建议的所有东西。当我调试代码时,我得到了这样的答案"源未找到"

我写了一个main方法来测试类,我得到:

org.apache.derby.client.am.SqlException: Syntax error: Encountered "','" at line 1, column 83.
    at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
    at org.apache.derby.client.am.Statement.completeExecuteImmediate(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
    at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
    at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
    at org.apache.derby.client.am.Statement.readExecuteImmediate(Unknown Source)
    at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
    at org.apache.derby.client.am.Statement.executeX(Unknown Source)
    at org.apache.derby.client.am.Statement.execute(Unknown Source)
    at com.example.expert_system.Database_engine.insertPhone(Database_engine.java:56)
    at com.example.expert_system.Database_engine.main(Database_engine.java:24)
第56行是stmt.execute("insert into " + tableName + " (producer, model, construction, display_size, system) values (" + db_producer + "','" + db_model + "','" + db_construction + "','" + db_display_size + "','" + db_system +"')");

但是一切都很好。我想是吧?

有什么建议吗??

因为它说你的SQL有语法错误。在你的SQL中你有:

…值(" + db_producer + "','"…

包含不匹配的单引号。

您的createConnection方法可能不成功,或者您的createStatement调用不成功,使"conn"为空

最新更新