我的小型數據庫(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 + " (producer, model, construction, display_size, system) values (" + db_producer + "','" + db_model + "','" + db_construction + "','" + db_display_size + "','" + db_system +"')");
但有一切都OK。我想是這樣?
有什麼建議?
哪個版本的Vaadin是。您使用的是?Knowledge.java中的哪一行是280? – miq 2011-12-25 15:25:19
我正在使用Vaadin Plug-in for Eclipse並且版本爲2.0.1。行280在insertClick方法中調用了buttonClick方法 – erni 2011-12-25 20:34:41
您是否嘗試過調試該代碼並查看哪個對象爲空?我很確定調試將顯示導致NullPointerException的對象。 – miq 2011-12-26 08:39:13