java.lang.NullPointerException
at de.steinwedel.messagebox.i18n.ButtonCaptionFactory.translate(ButtonCaptionFactory.java:39)
at de.steinwedel.messagebox.MessageBox.withButton(MessageBox.java:601)
at de.steinwedel.messagebox.MessageBox.withOkButton(MessageBox.java:633)
at de.steinwedel.messagebox.MessageBox.withOkButton(MessageBox.java:621)
As I cann see, you are trying to get Locale from Session:
Object value = VaadinService.getCurrentRequest().getWrappedSession().getAttribute(LANGUAGE_SESSION_KEY);
but in my case VaadinService.getCurrentRequest() is Null, because I want to show Message from Thread.
Is it possible to change this code or at least add a check?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think, moving the "try {" from line 45 to line 35 in the class ButtonCaptionFactory should solve your problem. If you have a better idea, tell me. I will build a new release after you have answered.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This will help to solve the NullPointer problem, but will not help to initialize the language.
I'm not a Vaadin expert, but why not to use VaadinSession.getCurrent() instead of VaadinService.getCurrentRequest().getWrappedSession()?
Actually I'm not sure if the Problem is not in my code, probably, you can give me a hint?
I'm starting my thread using UI.getCurrent().access:
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
final TaskRunWorkThread thread = new TaskRunWorkThread();
thread.start();
UI.getCurrent().setPollInterval(500);
}
});
According the documentation, VaadinService.getCurrentRequest() should not be null in the child thread, but not in my case (in the main thread it is not null). At the same time VaadinSession.getCurrent() is not null in both threads.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
I'm getting NullPointerException by creating a button:
MessageBox.createError().withCaption(caption).withHtmlMessage(msg).withOkButton().open();
java.lang.NullPointerException
at de.steinwedel.messagebox.i18n.ButtonCaptionFactory.translate(ButtonCaptionFactory.java:39)
at de.steinwedel.messagebox.MessageBox.withButton(MessageBox.java:601)
at de.steinwedel.messagebox.MessageBox.withOkButton(MessageBox.java:633)
at de.steinwedel.messagebox.MessageBox.withOkButton(MessageBox.java:621)
As I cann see, you are trying to get Locale from Session:
Object value = VaadinService.getCurrentRequest().getWrappedSession().getAttribute(LANGUAGE_SESSION_KEY);
but in my case VaadinService.getCurrentRequest() is Null, because I want to show Message from Thread.
Is it possible to change this code or at least add a check?
I think, moving the "try {" from line 45 to line 35 in the class ButtonCaptionFactory should solve your problem. If you have a better idea, tell me. I will build a new release after you have answered.
This will help to solve the NullPointer problem, but will not help to initialize the language.
I'm not a Vaadin expert, but why not to use VaadinSession.getCurrent() instead of VaadinService.getCurrentRequest().getWrappedSession()?
Actually I'm not sure if the Problem is not in my code, probably, you can give me a hint?
I'm starting my thread using UI.getCurrent().access:
According the documentation, VaadinService.getCurrentRequest() should not be null in the child thread, but not in my case (in the main thread it is not null). At the same time VaadinSession.getCurrent() is not null in both threads.
You are right, using VaadinSession.getCurrent() is better. I will create a new release at weekend.
BTW, https://vaadin.com/api/7.5.0/com/vaadin/ui/UI.html#access%28java.lang.Runnable%29 specifies, that VaadinService.getCurrentRequest() is undefined inside the Runnable. Therefore you get the NPE.
New version is released. Can you give me a feedback?