- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我花了 2 天的时间来解决我的问题并了解我错在哪里。我正在尝试使用 TodoService 在网格上显示项目并将数据添加到我的 SQL 中。但我收到错误:
我只是在 todoview 中输入 4 个字段,然后单击“保存”(הוסף) 按钮。我猜我的服务有问题。但我不明白什么。人们试图帮助我,但似乎没有任何作用。
java.lang.NullPointerException: null
at com.packagename.ui.views.TodoView.saveTodo(TodoView.java:111) ~[classes/:na]
at com.packagename.ui.views.TodoView.onComponentEvent(TodoView.java:127) ~[classes/:na]
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:373) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$dd1b7957$1(ComponentEventBus.java:264) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$2(ElementListenerMap.java:441) ~[flow-server-2.0.14.jar:2.0.14]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507) ~[na:na]
at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:441) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:59) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:64) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:378) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:359) ~[flow-server-2.0.14.jar:2.0.14]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507) ~[na:na]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:359) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:301) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:87) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:246) ~[flow-server-2.0.14.jar:2.0.14]
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:95) ~[vaadin-spring-12.0.6.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:352) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.22.jar:9.0.22]
at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]
TodoService.java
@Component
public class TodoService {
@Autowired
private JdbcTemplate jdbcTemplate;
public List<Todo> findAll() {
return jdbcTemplate.query(
"SELECT ID, TaskStatus, dudate,subject FROM todo",
(rs, rowNum) -> new Todo(rs.getLong("ID"),
rs.getLong("UserID"), rs.getLong("descriptionID"),rs.getString("taskstatus")));
}
public void update(Todo todo) {
jdbcTemplate.update("INSERT INTO todo (TaskStatus,dudate,subject,CustomerID) VALUES(?,?,?,?)",todo.getTaskStatus(),todo.getDudate(),todo.getSubject(),todo.getCustomerID());
}
}
Todo.java
public class Todo {
private long userID;
private String taskstatus;
private long ID;
private long customerID;
private long descriptionID;
private String taskStatus;
private String Subject;
private LocalDate Dudate;
public Todo() // Def Ctor
{
}
public Todo (String taskstatus,LocalDate dudate,String subject,long customerid){
this.customerID= customerid;
this.Subject = subject;
this.Dudate = dudate;
this.taskstatus = taskstatus;
}
public Todo(long id, long customerid, long descriptionid, String task) { // Ctor all
this.ID=id;
this.customerID=customerid;
this.descriptionID=descriptionid;
this.taskStatus=task;
}
public long getID() {
return ID;
}
public void setID(long ID) {
this.ID = ID;
}
public long getUserID() {
return userID;
}
public void setUserID(long userID) {
this.userID = userID;
}
public long getDescriptionID() {
return descriptionID;
}
public void setDescriptionID(long descriptionID) {
this.descriptionID = descriptionID;
}
public String getTaskStatus() {
return taskStatus;
}
public void setTaskStatus(String taskStatus) {
this.taskStatus = taskStatus;
}
public String getSubject() {
return Subject;
}
public void setSubject(String subject) {
this.Subject = subject;
}
public LocalDate getDudate() {
return Dudate;
}
public void setDudate(LocalDate dudate) {
this.Dudate = dudate;
}
public long getCustomerID() {
return customerID;
}
public void setCustomerID(long customerID) {
this.customerID = customerID;
}
}
TodoView.java
package com.packagename.ui.views;
@Route(value = NAV,layout = MainView.class)
public class TodoView extends Composite<Div> {
public static final String NAV = "todo";
public Todo todo = new Todo();
private Grid<Todo> todogrid = new Grid<>(Todo.class);
private Binder<Todo> binder = new Binder<>(Todo.class);
@Autowired
@SuppressWarnings( "SpringJavaAutowiredMembersInspection")
private TodoService service ;
private Button addButton = new Button("Save", // } catch (ValidationException ex) {
// ex.printStackTrace();
this::onComponentEvent);
public TodoView(){
//Layouts//
HorizontalLayout todofields = new HorizontalLayout();
VerticalLayout todoList = new VerticalLayout();
HorizontalLayout subjects = new HorizontalLayout();
todogrid.addThemeNames("no-border","no-row-borders","row-strips");
GridMultiSelectionModel<Todo> selectionModel = (GridMultiSelectionModel<Todo>) todogrid
.setSelectionMode(Grid.SelectionMode.MULTI);
selectionModel.selectAll();
//Layouts//
//Fields//
ComboBox<String> taskstatus = new ComboBox<>("TaskStatus:");
taskstatus.setItems("Completed","OnProgress","Cancelled");
TextField subject = new TextField();
subject.setLabel("נושא:");
TextField customerid = new TextField();
customerid.setLabel("שם הלקוח:");
DatePicker dudate = new DatePicker();
dudate.setClearButtonVisible(true);
dudate.setLabel("תאריך סיום:");
//Binder//
binder.forField(subject).bind(Todo::getSubject,Todo::setSubject);
binder.forField(dudate).bind(Todo::getDudate,Todo::setDudate);
binder.forField(taskstatus).bind(Todo::getTaskStatus,Todo::setTaskStatus);
binder.forField(customerid).withConverter(new StringToLongConverter(""))
.bind(Todo::getCustomerID,Todo::setCustomerID);
//Binder//
addButton.addClickShortcut(Key.ENTER);
addButton.setThemeName("primary");
//Fields//
todofields.add(subject,customerid,dudate,taskstatus,addButton);
todofields.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
todoList.setDefaultHorizontalComponentAlignment(FlexComponent.Alignment.BASELINE);
todofields.getElement().getStyle().set("margin-left","auto");
getContent().add(todofields,subjects,todoList,todogrid);
Direction.set(Direction.RTL);
}
private void saveTodo() {
service.update(todo);
}
private void updateGrid() {
List<Todo> todo = service.findAll();
todogrid.setItems(todo);
}
private void onComponentEvent(ClickEvent<Button> e) {
try {
binder.writeBean(todo);
System.out.println(todo.getCustomerID());
System.out.println(todo.getTaskStatus());
System.out.println(todo.getDudate());
System.out.println(todo.getSubject());
saveTodo();
updateGrid();
binder.readBean(new Todo());
// } catch (ValidationException ex) {
// ex.printStackTrace();
} catch (ValidationException ex) {
ex.printStackTrace();
}
}
}
最佳答案
我认为问题在于 Route 注解不是由 Spring Boot 管理的。因此,任何@Autowired都不起作用。您是否尝试过添加 @SpringComponent 注释( https://vaadin.com/api/vaadin-spring/12.0.6/com/vaadin/flow/spring/annotation/SpringComponent.html )?
关于java - 空指针异常 : null when trying to use jdbcTemplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58226021/
我刚刚遇到了一个非常奇怪的行为。这是代码: // So far everything's fine val x: Try[Try[Unit]] = Try(Try{}) x: scala.util.T
“输出”是一个序列化的 OpenStruct。 定义标题 try(:output).try(:data).try(:title) 结束 什么会更好? :) 最佳答案 或者只是这样: def title
我有以下元组 - (t1,t2) :(Try,Try) 我想检查两者是否成功或其中之一是否失败,但避免代码重复。像这样的东西: (t1,t2) match { case (Success(v1),Su
是否必须放置内部 try-with-resources 或其中一个 try-with-resources 中的所有内容都会自动关闭? try (BasicDataSource ds = Bas
有一点特殊,尝试创建一段 try catch 代码来处理 GoogleTokenResponse,但编译器在 try 时抛出异常错误。有什么想法吗? 错误信息: | Loading Grails 2.
它几乎可以在所有语言中找到,而且我大部分时间都在使用它。 我不知道它是内部的,不知道它是如何真正起作用的。 它如何在任何语言的运行时在 native 级别工作? 例如:如果在 try 内部发生 sta
为什么在 readFile2() 中我需要捕获 FileNotFoundException 以及稍后由 close( ) 方法,并且在 try-with-resources(inside readfi
我正在使用 Apache POI 尝试读取 Word 文件,但即使您使用过 Apache POI,这仍然应该是可以回答的。在 HWPF.extractor 包中有两个对象:WordExtractor
如果try-catch的catch block 中抛出异常,那么finally block 会被调用吗? try { //some thing which throws error } cat
这个问题已经有答案了: What's the purpose of try-with-resources statements? (7 个回答) 已关闭 3 年前。 我一直在查看代码,并且已经看到了对
这个问题已经有答案了: What's the purpose of try-with-resources statements? (7 个回答) 已关闭 3 年前。 我一直在查看代码,并且已经看到了对
我正在使用 Try::Tiny尝试捕捉。 代码如下: use Try::Tiny; try { print "In try"; wrongsubroutine(); # undefi
我想知道这样的代码是否会在抛出异常后总是中断而不继续运行,因此代码不会继续执行第二个 temp.dodaj(b)。 Avto *a = new Avto("lambo",4); Avt
我知道在try子句中必须有一个与资源关联的变量声明。 但是除了被分配一个通常的资源实例化之外,它是否可以被分配一个已经存在的资源,例如: public String getAsString(HttpS
我有一个写的方法。此方法仅扫描用户输入的整数输入。如果用户输入一个字符值,它将抛出一个输入不匹配异常,这是在我的 Try-Catch 语句中处理的。问题是,如果用户输入任何不是数字的东西,然后抛出异常
我注意到这不会编译: PrintWriter printWriter = new PrintWriter("test.txt"); printWriter.append('a'); printWrit
我经常看到人们写这样的代码: try: some_function() except: print 'something' 当我认为这样做更干净时: try: some_functio
该应用程序将在第二个显示器上正常显示内容。问题是当我旋转 iPad 时内容不会在 iPad 上旋转。 看过: http://developer.apple.com/library/ios/#qa/qa
我正在学习 java,我发现我不喜欢的一件事通常是当我有这样的代码时: import java.util.*; import java.io.*; public class GraphProblem
我使用 C++ 有一段时间了,对普通的 try/catch 很熟悉。但是,我现在发现自己在 Windows 上,在 VisualStudio 中编码以进行 COM 开发。代码的几个部分使用了如下内容:
我是一名优秀的程序员,十分优秀!