-1

I have a problem with Vaadin ; this is my code :

@SpringView(name = LoginView.VIEW_NAME)
public class LoginView extends Panel implements View {

    private static final long serialVersionUID = 4440163925650357979L;

    public static final String VIEW_NAME = "login";

    @Autowired
    private UiController controller;

    public LoginView() {
        super();
        System.out.println(controller);
    }
}

And the exception is like :

2017-01-17 10:20:32.649 ERROR 10176 --- [nio-8080-exec-8] com.vaadin.server.DefaultErrorHandler    : 

java.lang.NullPointerException: null
    at com.open.belgium.tonyrenard.vaadin.views.LoginView.lambda$0(LoginView.java:33) ~[classes/:na]

I'm not an expert with vaadin and I am totally lost. The dependences are ok ? I don't know...

It works and I change a point. Then, I rollback and it doesn't work anyway... Can you help me ?

EDIT : Controller is null and I don't understand why...

EDIT : I found the solution, my LoginView was not instantiated by Spring. Then, Spring will not instantiate the Controller. I have put off the new LoginView in the caller and the @Autowired works fine.

ReNaR
  • 169
  • 1
  • 2
  • 16
  • Possible duplicate of [Why is my Spring @Autowired field null?](http://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null) – khelwood Jan 17 '17 at 09:29
  • 1
    Then you need to do some debugging and figure out at least what variable is null. See [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – khelwood Jan 17 '17 at 10:01
  • To give you a great answer, it might help us if you have a glance at [ask] if you haven't already. It might be also useful if you could provide a [mcve]. – Mat Jan 17 '17 at 10:26
  • I have edit the post for clearly reading – ReNaR Jan 17 '17 at 10:35

3 Answers3

0

You need to instantiate your button.

private Button connect = new Button();
Chris M
  • 1,058
  • 1
  • 15
  • 26
0

Something in this:

event -> {this.controller.entree(log.getValue(), pwd.getValue());}

is null. According to the stack trace, the only thing that can be null is controller. If it were log or pwd, then the NullPointerException would occur inside UiController::entree.

EDIT: I am wrong above, everything in this lamda can be null, including log and pwd. Assuming controller cannot be null because it is injected, then it has to be log or pwd.

vagelis
  • 334
  • 3
  • 9
  • "Autowired" or not, the stack trace says it's null. Why not add a log statement in your constructor and / or lamda to see if it's null or not? – vagelis Jan 17 '17 at 10:09
  • I'm sorry, I am mistaken. Everything in the lamda can be null to cause that stack trace, not just `controller`. I will be editing my answer. – vagelis Jan 17 '17 at 10:10
  • I have test the variables, you're right. The controller is null. But, Why ? I don't understand the reason. – ReNaR Jan 17 '17 at 10:14
  • I am not familiar with what `Autowired` does (or Spring in general, for that matter), but maybe something is wrong with your object dependencies? – vagelis Jan 17 '17 at 10:22
  • @vagelis Sounds like you should look at [Why is my Spring Autowired field null?](http://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null) then, as someone suggested an hour ago. – khelwood Jan 17 '17 at 10:26
  • @khelwood Nope, doesn't sound like that at all. The OP's trouble was figuring out what caused the NullPointerException and that's what I addressed. He however, yes, should definitely take a look. :) – vagelis Jan 17 '17 at 10:36
  • Thank you for the help. Bye – ReNaR Jan 17 '17 at 10:47
0

I found the solution, my LoginView was not instantiated by Spring.

Therefore, Spring will not instantiate the Controller.

I @Autowired the LoginView in the "caller" and the @Autowired for the Controller works fine.

ReNaR
  • 169
  • 1
  • 2
  • 16