Android Question B4J to B4A

I have created a b4a app from a sample java app (B4ATables Inline Editing) to help with my understanding of differences etc

The program runs ok until I actually try to edit a cell. The program crashes at that point

However if I step through the program from line 69 It will work

I have tried putting a sleep(0) after line 68 but that makes no difference

Could someone have a look at it and advise what I have missed please

Many Thanks
 

Attachments

  • b4a.zip
    13.5 KB · Views: 67
Solution
The Tag value is Null, you can fix it like this.
B4X:
Private Sub SetEditableControlLayout (SelectedControl As FocusedCell)
    Dim c As B4XTableColumn = mTable.GetColumn(SelectedControl.ColumnId)
    CurrentlyFocusedCell.VisibleIndex = mTable.VisibleRowIds.IndexOf(SelectedControl.RowId)
    Dim p As B4XView = c.CellsLayouts.Get(CurrentlyFocusedCell.VisibleIndex + 1) '+1 because of the header
    
    Log( "NumberOfViews: "& p.NumberOfViews)
    If SelectedControl.View.Parent <> p Then
        If p.GetView( p.NumberOfViews - 1).IsInitialized Then
            Log( "IsInitialized")
            Log( "Type: "& GetType( p.GetView( p.NumberOfViews - 1)))
            Log( "Text: "& p.GetView( p.NumberOfViews - 1).Text)
            Log( "Tag: "&...

Erel

B4X founder
Staff member
Licensed User
Longtime User
from a sample java app
This is a B4J app. Not Java app.

The program crashes at that point
Better to post the error message and the relevant code.

Inline editing is a B4J module. The reason that I haven't ported it to B4A is that handling the soft keyboard is more difficult and with the small screen you will probably get better results with a form: https://www.b4x.com/android/forum/t...ditable-b4xtable-form-example.104766/#content
 
Upvote 0
Yes, of course it is sorry

** Activity (main) Pause event (activity is not paused). **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 69 (InlineEditing)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.example.inlineediting._seteditablecontrollayout(inlineediting.java:344)
at b4a.example.inlineediting._makecelleditable(inlineediting.java:219)
at b4a.example.inlineediting._cellclicked(inlineediting.java:95)
at b4a.example.b4xmainpage._b4xtable1_cellclicked(b4xmainpage.java:130)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1085)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1048)
at b4a.example.b4xtable$ResumableSub_CellClicked.resume(b4xtable.java:1508)
at b4a.example.b4xtable._cellclicked(b4xtable.java:1249)
at b4a.example.b4xtable._lbl_click(b4xtable.java:3285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7155)
at android.view.View.performClickInternal(View.java:7124)
at android.view.View.access$3500(View.java:808)
at android.view.View$PerformClick.run(View.java:27370)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:359)
at android.app.ActivityThread.main(ActivityThread.java:7418)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
*** Service (starter) Create ***

As I say the screen size is not a problem and it works if I put a break-point in then step into line 69

EDIT:

If these 3 lines of code are removed it seems to work. Is that a real solution?
B4X:
'        If p.GetView(p.NumberOfViews - 1).Tag = "TextFlow" Then
'            p.GetView(p.NumberOfViews - 1).RemoveViewFromParent 'remove the special TextFlow control that is added to highlight search result
'        End If
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
The Tag value is Null, you can fix it like this.
B4X:
Private Sub SetEditableControlLayout (SelectedControl As FocusedCell)
    Dim c As B4XTableColumn = mTable.GetColumn(SelectedControl.ColumnId)
    CurrentlyFocusedCell.VisibleIndex = mTable.VisibleRowIds.IndexOf(SelectedControl.RowId)
    Dim p As B4XView = c.CellsLayouts.Get(CurrentlyFocusedCell.VisibleIndex + 1) '+1 because of the header
    
    Log( "NumberOfViews: "& p.NumberOfViews)
    If SelectedControl.View.Parent <> p Then
        If p.GetView( p.NumberOfViews - 1).IsInitialized Then
            Log( "IsInitialized")
            Log( "Type: "& GetType( p.GetView( p.NumberOfViews - 1)))
            Log( "Text: "& p.GetView( p.NumberOfViews - 1).Text)
            Log( "Tag: "& p.GetView( p.NumberOfViews - 1).Tag)
        End If
        If p.GetView(p.NumberOfViews - 1).Tag <> Null And p.GetView(p.NumberOfViews - 1).Tag = "TextFlow" Then
            p.GetView(p.NumberOfViews - 1).RemoveViewFromParent 'remove the special TextFlow control that is added to highlight search result
        End If
        p.AddView(SelectedControl.View, 0, 0, p.Width, p.Height)
        p.GetView(c.LabelIndex).Visible = False
        SelectedControl.View.BringToFront
        CurrentlyFocusedCell.View.RequestFocus
    Else
        SelectedControl.View.SetLayoutAnimated(0, 0, 0, p.Width, p.Height)
    End If
End Sub
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
NumberOfViews: 1
IsInitialized
Type: android.widget.TextView
Text: Item #1
Tag: null
 
Upvote 1
Solution
Top