callAction giving nullPointerException
3 posts
• Page 1 of 1
callAction giving nullPointerException
Hi,
I have following code in my Session
but when I call the method getUserEmplName from a workscreen with
I am getting a NullPointerException
Any idea where this goes wrong?
Luc
I have following code in my Session
- Code: Select all
public DBStorage getVUserSession() throws Exception
{
DBStorage dbsVUserSession = (DBStorage)get("vUserSession");
if (dbsVUserSession == null)
{
dbsVUserSession = new DBStorage();
dbsVUserSession.setWritebackTable("v_user_grup_admi");
dbsVUserSession.setDBAccess(getDBAccess());
dbsVUserSession.open();
put("vUserSession", dbsVUserSession);
}
return dbsVUserSession;
}
public Object getUserEmplName() throws Exception
{
DBStorage dbVU = getVUserSession();
ICondition pFilter = new Equals("USERNAME", TriggerAPI.getCurrentUserName());
IBean rowUserLogin = new Bean();
rowUserLogin = dbVU.fetchBean(pFilter);
return rowUserLogin.get("EMPL_NAME");
}
but when I call the method getUserEmplName from a workscreen with
- Code: Select all
public void onActivate() throws Throwable
{
labelUser.setText(getConnection().callAction("getUserEmplName").toString());
}
I am getting a NullPointerException
- Code: Select all
java.lang.NullPointerException
at be.moonfox.apps.max.Session.getUserEmplName(Session.java:250)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.sibvisions.util.Reflective.call(Reflective.java:290)
at com.sibvisions.rad.server.GenericBean.invoke(GenericBean.java:808)
at com.sibvisions.rad.server.GenericBean.invoke(GenericBean.java:722)
at com.sibvisions.rad.server.GenericBean.invoke(GenericBean.java:777)
at com.sibvisions.rad.server.DefaultObjectProvider.invoke(DefaultObjectProvider.java:430)
at com.sibvisions.visionx.server.VisionXObjectProvider.invoke(Unknown Source)
at be.moonfox.apps.max.screens.ProductDesign.<null>.getUserEmplName(Unknown Source)
at com.sibvisions.rad.server.AbstractSession.executeWithSessionContext(AbstractSession.java:770)
at com.sibvisions.rad.server.AbstractSession.executeIntern(AbstractSession.java:722)
at com.sibvisions.rad.server.AbstractSession.execute(AbstractSession.java:690)
at com.sibvisions.rad.server.Server.executeIntern(Server.java:2355)
at com.sibvisions.rad.server.Server.execute(Server.java:660)
at com.sibvisions.rad.server.DirectServerConnection.call(DirectServerConnection.java:305)
at javax.rad.remote.AbstractConnection.callAction(AbstractConnection.java:757)
at be.moonfox.apps.max.screens.ProductDesignWorkScreen.onActivate(ProductDesignWorkScreen.java:127)
at com.sibvisions.apps.projx.screens.DataSourceWorkScreen.activate(DataSourceWorkScreen.java:607)
at com.sibvisions.apps.projx.screens.DataSourceWorkScreen.notifyVisible(DataSourceWorkScreen.java:372)
at com.sibvisions.apps.projx.ProjX.openContainer(ProjX.java:3505)
at com.sibvisions.apps.projx.ProjX.openWorkScreen(ProjX.java:2339)
at com.sibvisions.apps.projx.ProjX.openWorkScreen(ProjX.java:899)
at javax.rad.application.genui.RemoteWorkScreenApplication.openWorkScreen(RemoteWorkScreenApplication.java:82)
at com.sibvisions.apps.projx.ProjX.doOpenWorkScreen(ProjX.java:6968)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javax.rad.util.EventHandler$ListenerHandler.dispatchEvent(EventHandler.java:1042)
at javax.rad.util.EventHandler.dispatchEvent(EventHandler.java:608)
at javax.rad.util.RuntimeEventHandler.dispatchEvent(RuntimeEventHandler.java:73)
at com.sibvisions.rad.ui.swing.impl.component.SwingAbstractButton.actionPerformed(SwingAbstractButton.java:396)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)
at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1020)
at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1064)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6632)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6397)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Any idea where this goes wrong?
Luc
- lucdep
- Posts: 53
- Joined: Wed Oct 10, 2018 12:01 pm
Re: callAction giving nullPointerException
I'm not sure if someone here can help you with debugging your code? Your question is not JVx specific and more a general development question?
The line number:
doesn't match with your code snippet.
But as usual: If you have a NPE in line 250, there is a null object in this line.
What I see is that you create a bean for fetchBean?
Its not necessary to do more than this:
It's possible that fetchBean returns null if no user was found.
I would write the method a little bit different:
Are you sure that the user-info should be set on Activate - every time? Isn't it good enough to retrieve the user-info only once after login?
But sure, it's you application and your business logic
The line number:
- Code: Select all
at be.moonfox.apps.max.Session.getUserEmplName(Session.java:250)
doesn't match with your code snippet.
But as usual: If you have a NPE in line 250, there is a null object in this line.
What I see is that you create a bean for fetchBean?
- Code: Select all
IBean rowUserLogin = new Bean();
rowUserLogin = dbVU.fetchBean(pFilter);
Its not necessary to do more than this:
- Code: Select all
IBean rowUserLogin = dbVU.fetchBean(pFilter);
It's possible that fetchBean returns null if no user was found.
I would write the method a little bit different:
- Code: Select all
IBean bean = getVUserSession().fetchBean(new Equals("USERNAME", TriggerAPI.getCurrentUserName()));
if (bean == null)
{
//or return en empty string?
throw new IllegalArgumentException("User was not found in User-Session list!");
}
else
{
return rowUserLogin.get("EMPL_NAME");
}
And also your client code is not null aware:
[code]
Object result = getConnection().callAction("getUserEmplName");
if (result != null)
{
labelUser.setText(result.toString());
}
else
{
???
}
Are you sure that the user-info should be set on Activate - every time? Isn't it good enough to retrieve the user-info only once after login?
But sure, it's you application and your business logic
- johnit
- Posts: 45
- Joined: Fri Nov 16, 2012 5:58 pm
Re: callAction giving nullPointerException
Thanks for your reply. Things are working now.
Regards,
Luc
Regards,
Luc
- lucdep
- Posts: 53
- Joined: Wed Oct 10, 2018 12:01 pm
3 posts
• Page 1 of 1