为什么我会收到 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);
}
请告诉我我做错了什么。
好的,我已经检查了你建议的所有内容。 当我调试代码时,我得到这样的答案“找不到源”,
我编写了一个主要方法来测试该类,我得到:
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 + " (生产者,模型、构造、display_size、系统)值 (" + db_ Producer + "','" + db_model + "','" + db_construction + "','" + db_display_size + "','" + db_system +"')");
但一切正常。我想是这样吗?
有什么建议吗?
I have big problem with my small database(DERBY) application. I am getting such an error when I click the button:
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
I am getting this only when I am trying to call the method from class 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)
{
}
}
And the code of form methods:
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);
}
Please tell me what am I doing wrong.
Ok I have checked all things you suggested.
When I debug the code I got such an answer "source not found"
I wrote an main method to test the class and I am getting:
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)
line 56 is stmt.execute("insert into " + tableName + " (producer, model, construction, display_size, system) values (" + db_producer + "','" + db_model + "','" + db_construction + "','" + db_display_size + "','" + db_system +"')");
But there is everything OK. I think so?
Any suggestions ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如它所说,你的 SQL 有语法错误。在你的 SQL 中你有:
其中包含不匹配的单引号。
As it says your SQL has a syntax error. In your SQL you have:
which contains an unmatched single quote.
您的 createConnection 方法可能不会成功,或者您的 createStatement 调用不会成功,从而将“conn”保留为 null。
Your createConnection method probably doesn't succeed, or your createStatement call doesn't succeed, leaving "conn" as null.