У меня большая проблема с приложением небольшой базы данных (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 +"')");
Но там все в порядке. Я так думаю?
Есть предложения ??