B4J Question I get an error on form.show

Wien.Mart

Member
Licensed User
Longtime User
I click an item from one of three table views and assign the value to a variable. I use the value to launch a form. I get an error at the End Sub.

part of the code is something like:

Sub TableView1_SelectedRowChanged(Index As Int, Row() As Object)
Dim f As Int
If Index > -1 Then
TV = 1
f = GetCellValue(Index, 0)
End If
End Sub

'''table view 2 and 3 deleted since it is almost same as table view 1 code

Sub GetCellValue(RowIndex As Int, CellIndex As Int) As String
Return GetLabel(RowIndex, "0").Text
End Sub

Sub GetLabel(RowIndex As Int, CellIndex As Int) As Label
If TV = 1 Then
Dim row() As Object = TableView1.Items.Get(RowIndex)
Main.t= row(CellIndex)
form1.show

Else if TV = 2 Then
Dim row() As Object = TableView2.Items.Get(RowIndex)
Main.t= row(CellIndex)
form2.show
Else if TV = 3 Then
Dim row() As Object = TableView3.Items.Get(RowIndex)
Main.t= row(CellIndex)
form3.show
End If
End Sub

form1 loads then I get an error on line 116 which is an End Sub

line: 116 is End Sub

Waiting for debugger to connect...
Program started.
(Exception) Not initialized
Error occurred on line: 116
java.lang.NullPointerException
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:606)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Before showing the form you have to call the method initialize

This is true for almost all the classes used in b4x language
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Your GetLabel routine implies it returns a label, but I cannot see any return statement in the rountine.
It will probably return a null as a default , and this 'could' trigger the NullPointerException error.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This routine
B4X:
Sub GetCellValue(RowIndex As Int, CellIndex As Int) As String
Return GetLabel(RowIndex, "0").Text
End Sub

is expecting GetLabel(..) to return a Label, so it can obtain the .Text value and return it to the TableView1_SelectedRowChanged routine.

As you do not return a Label, it probably fails on the GetLabel(RowIndex, "0").Text

You could try returning the Label from the selected cell (if it has one), and check that GetLabel(RowIndex, "0") does not return a null.

Seeing such a short section of code makes it difficult to work out what you are trying to do.
 
Upvote 0
Top