B4J Question [SOLVED] [B4XTable] Crashing When Attempting To Add One Row

cklester

Well-Known Member
Licensed User
I'm getting a crash attempting to execute this code:

B4X:
    Dim sql As String
    sql = $"INSERT INTO data VALUES (?,?,?,?,?)"$
    Log(sql)
    ' these are all strings
    Log(bbo.pair)
    Log(txt_BestBid.Text)
    Log(txt_BestAsk.Text)
    Log(txt_Spread.text)
    Log(txt_LastPrice.text)
    
    table_SubscribedPairs.sql1.ExecNonQuery2(sql, Array As String(bbo.pair,txt_BestBid.Text,txt_BestAsk.Text,txt_Spread.text,txt_LastPrice.text))

The crash message is as follows:

INSERT INTO data VALUES (?,?,?,?,?)
ltc-btc
0 / 0
0 / 0
0
0
Error occurred on line: 738 (B4XMainPage)
java.lang.NullPointerException
at anywheresoftware.b4j.objects.SQL.ExecNonQuery2(SQL.java:199)

What should I look for to resolve this issue?
 

josejad

Expert
Licensed User
Longtime User
Probably you have some "Null" value in your data. Check your values and change the 'null' to an appropiate value before execnonquery
 
Upvote 0

cklester

Well-Known Member
Licensed User
Please post the full error message from the logs.

Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
INSERT INTO data VALUES (?,?,?,?,?)
eth-btc
0 / 0
0 / 0
0
0
Error occurred on line: 738 (B4XMainPage)
java.lang.NullPointerException
at anywheresoftware.b4j.objects.SQL.ExecNonQuery2(SQL.java:199)
at b4j.example.b4xmainpage._clv_exchangepairs_itemclick(b4xmainpage.java:2247)
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:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:509)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:472)
at b4j.example.customlistview$ResumableSub_PanelClickHandler.resume(customlistview.java:808)
at b4j.example.customlistview._panelclickhandler(customlistview.java:751)
at b4j.example.customlistview._panel_mouseclicked(customlistview.java:742)
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:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:109)
at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3564)
at javafx.graphics/javafx.scene.Scene$ClickGenerator.access$8200(Scene.java:3492)
at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3860)
at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1200(Scene.java:3579)
at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2588)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

cklester

Well-Known Member
Licensed User
Probably you have some "Null" value in your data. Check your values and change the 'null' to an appropiate value before execnonquery

Where would the Null value be? You can see from the Log() output that none of those values are Null. Do you mean somewhere else?
 
Upvote 0

cklester

Well-Known Member
Licensed User
This causes the same error:

B4X:
table_SubscribedPairs.sql1.ExecNonQuery2(sql, Array As String("1","2","3","4","5"))
 
Upvote 0

cklester

Well-Known Member
Licensed User
I guess that you accessing sql1 before the database was created. You must first call Table.SetData.

Yes, that could be the case. I haven't yet used SetData because the table starts blank. The user will manually add rows to the table with button clicks.

How do I initialize the internal database without creating any records? Do I just need to test for IsInitialized and then use SetData() or sql1, whichever is appropriate?
 
Upvote 0

cklester

Well-Known Member
Licensed User
Is this an appropriate way around this issue?

B4X:
    Try
        table_SubscribedPairs.sql1.ExecNonQuery2(sqlq, Array As String(bbo.pair,txt_BestBid.Text,txt_BestAsk.Text,txt_Spread.Text,txt_LastPrice.Text))
    Catch
'        Log(LastException)
        Dim l As List
        l.Initialize
        l.Add(Array(bbo.pair,txt_BestBid.Text,txt_BestAsk.Text,txt_Spread.Text,txt_LastPrice.Text))
        table_SubscribedPairs.SetData(l)
    End Try
 
Upvote 0

cklester

Well-Known Member
Licensed User
No.
Better to always call SetData. I believe that you can call it with an empty list and it will work. Try it.

Yes! So, I simply call SetData() with an empty list to "initialize" the B4XTable, to make it ready for further input down the line.

This is working now. Thank you!
 
Upvote 0
Top