Android Question Error using "IME" for "B4XFloatTextField"

vhd_bgh

Member
Hi
I want to use "IME" for "B4XFloatTextField".

In the test program, The following line was executed correctly:
B4X:
Dim ET As EditText = B4XFloatTextField1.TextField

But... in the main program, this line gives the following error:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 468)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.B4XViewWrapper.getObject()' on a null object reference
    at b4a.example.main._activity_create(main.java:468)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5307)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

What do you think is the problem?
 

vhd_bgh

Member
The original code is long. I put a piece of it(only Activity_Create sub where the error occurs): (Note lines 17 , 18 and 19)
B4X:
Sub Activity_Create(FirstTime As Boolean)
    navigationDrawer.Initialize2("", Activity, navigationDrawer.DefaultDrawerWidth, navigationDrawer.GRAVITY_START)
    Activity.LoadLayout("mainLayout")
    navigationDrawer.InitDrawerToggle
    mainToolBar.InitMenuListener
    navigationDrawer.NavigationView.LoadLayout("mainLayoutNavigationHeaderItems", navigationDrawer.DefaultHeaderHeight)
    rPermission.CheckAndRequest("android.permission.ACCESS_FINE_LOCATION")
    rPermission.CheckAndRequest("android.permission.ACCESS_COARSE_LOCATION")
    bitmapDrawable = xml.GetDrawable("round_add_black_24")
    Activity.AddMenuItem3("Add Device", "Add", bitmapDrawable.Bitmap, True)
    If File.Exists(File.DirInternal, "Prj1Database.db")=False Then
        File.Copy(File.DirAssets, "Prj1Database.db", File.DirInternal, "Prj1Database.db")
    End If
    sql.Initialize(File.DirInternal, "Prj1Database.db", True)
    RefreshMainCustomListView

    IME.Initialize("")
    Dim tempET As EditText = configNameDialogEditText.TextField
    IME.SetCustomFilter(tempET, tempET.INPUT_TYPE_TEXT, "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789")

End Sub

In debug mode, this error occurs on line 17 :
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 412 (B4XFloatTextField)
java.lang.RuntimeException: Class instance was not initialized (b4xfloattextfield)
    at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
    at b4a.example.b4xfloattextfield._gettextfield(b4xfloattextfield.java:73)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5307)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

(It should be noted that the "B4XFloatTextField" is used and loaded in a "dialog" window)
2020-09-25 22_08_04-mainLayoutConfigNameDialog - (1-Main) Visual Designer.png
 
Last edited:
Upvote 0

vhd_bgh

Member
1. You are not handling the permissions correctly.
According to your video tutorial, I changed the above "permissions" part as follows. is it right?
B4X:
    rPermission.CheckAndRequest(rPermission.PERMISSION_ACCESS_COARSE_LOCATION)
    rPermission.CheckAndRequest(rPermission.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result=False Then
        ExitApplication
    End If

And another question☺
Could permissions also cause me this problem?
MLwifi library doesn't work on samsung devices!
 
Upvote 0

vhd_bgh

Member
2. I don't see that you are loading the dialog layout.

in this simple example:
B4X:
Sub Globals
    Private B4XFloatTextField1 As B4XFloatTextField
    Dim IME As IME
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("mainLayout")
    Dim ed1 As EditText = B4XFloatTextField1.TextField
    IME.Initialize("")
    IME.SetCustomFilter(ed1, ed1.INPUT_TYPE_TEXT, "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789")
End Sub

Sub Button1_Click
    Dim cd As CustomLayoutDialog
    Dim sf As Object = cd.ShowAsync("", "", "Cancel", "", Null, False)
    cd.SetSize(100%x, 300dip)
    Wait For (sf) Dialog_Ready (DialogPanel As Panel)
    DialogPanel.LoadLayout("layout1")
End Sub
(note that: B4XFloatTextField1 is in "layout1" and Dialog loads it")

in debug mode and in line 8 above, this error occurs:
B4X:
Copying updated assets files (10)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 412 (B4XFloatTextField)
java.lang.RuntimeException: Class instance was not initialized (b4xfloattextfield)
    at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
    at b4a.example.b4xfloattextfield._gettextfield(b4xfloattextfield.java:71)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5307)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Why not initialize the "B4XFloatTextField1" before loading his layout("layout1")?
 
Last edited:
Upvote 0
Top