B4J Question Resize Columns in TableView

DMW

Member
Licensed User
Longtime User
Hello (it's me again),

This makes my hair to disappear....

Obviously there is something that I miss here but I seems to be lost.

Based on the following thread:
https://www.b4x.com/android/forum/threads/tableview-content-resize.70348/

I Add / Delete / Update data (using a SQLite DB) in a TableView and after these operations I want to resize the columns so they fit to their contents.

This is the main sub:
B4X:
Sub ResizeToFit(tv As TableView, ColumnIndex As Int)
   Dim tvjo As JavaObject = tv
   Dim r As Reflector
   r.Target = tvjo.RunMethod("getSkin", Null)
   r.RunMethod4("resizeColumnToFitContent", Array(tvjo.RunMethodJO("getColumns", Null).RunMethod("get", Array(ColumnIndex)), -1), _
                   Array As String("javafx.scene.control.TableColumn", "java.lang.int"))
End Sub

In the subs I make the following calls with the assumption of a zero-based columns count:
B4X:
...
Dim iCounter As Int
For iCounter = 0 To tvSoftware.ColumnsCount -1
     ResizeToFit(tvSoftware, iCounter)
Next
...

When executing I get the following error message:
(NullPointerException) java.lang.NullPointerException

Please help me out.

TIA,
Dennis
 

DMW

Member
Licensed User
Longtime User
Hello.

Sorry, I don't have any hidden column(s).

During the start of the program the sub ResizeToFit is called after populating the TableView.
By removing the Try...Catch no error message is received?!

However, when adding a record, deleting a record and updating a record the following error is received. The line 108 refers to the last line in the sub ResizeToFit:

Waiting for debugger to connect...
Program started.
ExecuteMemoryTable: SELECT Software FROM v_Main ORDER BY Software;
ExecuteMemoryTable: SELECT Category FROM tbl_Category;
Error occurred on line: 108 (Main)
java.lang.NullPointerException
at com.sun.javafx.scene.control.skin.TableViewSkin.resizeColumnToFitContent(TableViewSkin.java:257)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.agraham.reflection.Reflection.runmethod(Reflection.java:168)
at anywheresoftware.b4j.agraham.reflection.Reflection.RunMethod4(Reflection.java:932)
at b4j.licman.main._resizetofit(main.java:479)
at b4j.licman.main._btdelete_action(main.java:815)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:226)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

DMW

Member
Licensed User
Longtime User
Hello again,

#1 When running a small project it works well.
#2 I added a button and added the code to it. When running it it also works as expected.

#3 After a DB operation (Add/Delete/Update) the code is executed and then it stops and reports the error.

In other words, running it as standalone code while running it after a DB operation does not work. The DB Utils module is in use as well as the jSQL library.
 
Upvote 0
Top