B4J Question [ABMaterial] Web app with MsSQl database - b4a.BA Error

Bladimir Carrillo

Member
Licensed User
Longtime User
This error is related to web app posted here https://www.b4x.com/android/forum/threads/web-app-with-mssql-database.71243/#post-455994

Message related to b4a.BA appears some times after any page load
The error are showing from I has implemented a module to send messages to B4A android mobile app using websockets (appears at any time when I am not sending remote mesagges to device):

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeExcepti
on: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketMo
dule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(Simple
MessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run
(WebSocketModule.java:195)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Nul
lPointerException
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:471)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:409)
at sts.sismac.net.st_edit._page_parseevent(st_edit.java:1625)
at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 10 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
... 16 more
Caused by: java.lang.NullPointerException
at sts.sismac.net.abmshared._connectnavigationbar(abmshared.java:610)
at sts.sismac.net.st_edit._connectpage(st_edit.java:660)
at sts.sismac.net.st_edit._page_ready(st_edit.java:1659)
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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 17 moreThank you in advance,

Any ideas ?
 

Bladimir Carrillo

Member
Licensed User
Longtime User
Can you post the code of ConnectNavigationBar? Run it in debug mode to see the exact error line.

code of ConnectNavigationBar:
B4X:
Sub ConnectNavigationBar(page As ABMPage)
   ' Clear the dummies we created in BuildNavigationBar
   page.NavigationBar.Clear
   If page.ws.Session.GetAttribute("IsAuthorized") = "true" Then
     page.NavigationBar.AddSideBarItem("LogOff", DB.smVar(page,5), "mdi-action-lock-open", "../LoginPage/sismac-login.html")

     page.NavigationBar.AddSideBarItem("ST_Lst", "Consultar solicitudes", "mdi-action-search", "../ST_List/st_list.html")
     page.NavigationBar.AddSideBarDivider("")

     page.NavigationBar.AddSideBarItem("ST_Nue", "Nueva solicitud", "mdi-content-add-circle-outline", "../ST_Edit/st_edit.html")
     page.NavigationBar.AddSideBarDivider("")

   Else
     page.NavigationBar.AddSideBarItem("LogOn", "Iniciar sesión", "mdi-action-lock-outline", "../LoginPage/sismac-login.html")
   End If
   page.NavigationBar.AddSideBarDivider("")
    
End Sub

I am testing in debug mode and the error do not appears; appears sporadically on release mode.

Similar error is showing in other Sub ...
No component found with id inpuser
No component found with id inppass
No component found with id inpcc
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:195)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:471)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:417)
at sts.sismac.net.loginpage._page_parseevent(loginpage.java:394)
at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 10 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
... 16 more
Caused by: java.lang.NullPointerException
at sts.sismac.net.loginpage._msbtn1_clicked(loginpage.java:254)
at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 17 more

On this case, considering the portion of code ...
Caused by: java.lang.NullPointerException
at sts.sismac.net.loginpage._msbtn1_clicked(loginpage.java:254)

Code of msbtn1_clicked on loginpage:
B4X:
Sub msbtn1_Clicked(Target As String)
   page.Pause
  
   Dim inpUser As ABMInput = page.Component("inpuser")
   Dim inpPass As ABMInput = page.Component("inppass")
   Dim inpCc As ABMInput = page.Component("inpcc")

   Dim jStr As JStringFunctions
   jStr.Initialize

   Dim Nm_Usr As String = inpUser.Text
   Dim Pw_Usr As String = DB.SHA2(inpPass.Text)
   Dim Id_CCs As Long = jStr.Val(inpCc.Text) +10000

   Dim usrSQL As SQL = DB.pool.GetConnection

   Try
     Dim qry As String = $"SELECT um.ID_Usr idm, up.ID_Usr id, up.ID_UsrMod md, up.Nm_Usr us, up.ID_Empl em, e.Nomb1 nm, e.Apell1 ap, e.ID_Dpto dp, e.ID_Secc sc
               FROM Users um,
               SM_Usr up INNER JOIN Pers e ON up.ID_Empl=e.ID_Empl
               WHERE up.Nm_Usr = ? AND up.Pw_Usr = ? AND um.ID_Usr = ?"$

     Dim m As Map = DBUtils.ExecuteMap(usrSQL, qry, Array As String(Nm_Usr,Pw_Usr,Id_CCs))

     usrSQL.Close
    
   Catch
     usrSQL.Close
     Log(LastException)
     page.Resume
     Return
   End Try

   Dim pwInit as String = "1m2nb3jh3i2 3k12hk3jhkrh2 k3jhrk32jrh k3jhrk2j3hrkb3"
   If m.IsInitialized = True Then
     If Pw_Usr = pwInit Then
       DB.smVar_Set(page,2,"" & m.Get("us"))
       DB.smVar_Set(page,5,"" & m.Get("nm") &  " " & m.Get("ap"))
       ABMShared.NavigateToPage(ws, "../" & RsetpwdPage)

     Else
       ws.Session.SetAttribute("IsAuthorized", "true")
       ws.Session.SetAttribute("authType", "local")
       ws.Session.SetAttribute("authName", inpUser.Text)

       ABMShared.NavigateToPage(ws, "../" & InitialPage)
     End If
    Log("LOGIN OK")

   Else
     Log("LOGIN X")

   End If
  
   page.Resume
End Sub

Regards
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Could you please prefix your issues with [ABMaterial] when appropriate?

I look at (study) these posts to see what others find - and learn. Without the prefix, I don't know if you are talking about standard B4J or ABM - or both and may miss an important post...

I need all the knowledge I can get, cause this can get tricky - fast...

Thanks my friend.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
So does mine, so I see your point. More ABM and less B4J. Thanks.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
In ConnectNavigationBar() build in an extra (log) check to see if page.ws <> null. Could be useul info.
Sorry, is this responding to the correct post?

Disregard this comment...
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
This may be the cause of several problems you encounter (loops, sessions lost, slow connections):

It appears in the latest version I did add the b4j_ws.min.js to the core.min.js library. The result was sessioncreator was NEVER used. It was first noticed on Apple devices (loops in reloading) and once I've split them up again, ABMSessionCreator was used and everything is fine. Maybe on slow connections, it does something similar (not getting the right GetSession). Will be changed back in 2.00.
 
Upvote 0
Top