I have moved forward and almost got my app to basically work.  However I am porting the BLE scan example
to a B4XPages type application. I have run into an issue trying to get the BLE2 library functions/events to callback
to the Subs that were in the old "Main" module but are now in "B4XMainPage" module.
Here is the BLE2 handler for data available event in Starter with my commented out line to try to call the function:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
and the function it is trying to call which is in B4XMainPage:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Problem is just after compile and sending to the device (B4Xbridge) it tosses this:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
A note that the calls from Starter B4XPages.MainPage.DoDataAvailable( ServiceId, Characteristics ) works
as it did in the original example.
Sub BLEman_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double) also works well
as it did in the activity example it came from.
I just can't get the B4XPages.MainPage.StateChanged( State ) call back to work, won't run, crashes Java?
I added a parameter to StateChanged thinking that might be it? No change. Of the 3 call back functions
the two with parameters work, this one with out a parameter crashes java at runtime.
That's it, hope I'm clear on it. I'll attache the project files too.
Thanks in advance,
Marc
			
			to a B4XPages type application. I have run into an issue trying to get the BLE2 library functions/events to callback
to the Subs that were in the old "Main" module but are now in "B4XMainPage" module.
Here is the BLE2 handler for data available event in Starter with my commented out line to try to call the function:
			
				BLE Event Stub for State Changed:
			
		
		
		Sub BLEman_StateChanged (State As Int)
    LogColor("BLEman StateChanged = "&State,Colors.Green)
    Select State
        Case BLEman.STATE_POWERED_OFF
            currentStateText = "POWERED OFF"
        Case BLEman.STATE_POWERED_ON
            currentStateText = "POWERED ON"
        Case BLEman.STATE_UNSUPPORTED
            currentStateText = "UNSUPPORTED"
    End Select
    currentState = State
    B4XPages.MainPage.StateChanged( State )
End Suband the function it is trying to call which is in B4XMainPage:
			
				BLE2 Event Sub:
			
		
		
		Sub StateChanged ( state As Int)
  Log("in StateChanged..."&state)
    lblState.Text = Starter.currentStateText
    If Starter.connected Then
        lblDeviceStatus.Text = "Connected: " & Starter.ConnectedName
    Else
        lblDeviceStatus.Text = "Not Connected"
    End If
    btnDisconnect.Enabled = Starter.connected
    btnScan.Enabled = Not(Starter.connected)
    pbReadData.Visible = False
    pbScan.Visible = False
    btnReadData.Enabled = Starter.connected
    btnScan.Enabled = (Starter.currentState = Starter.BLEman.STATE_POWERED_ON) And Starter.connected = False
End SubProblem is just after compile and sending to the device (B4Xbridge) it tosses this:
			
				Runtime Java error trail sub set::
			
		
		
		*** Debugger waiting for connection (1) ***
After accept
*** Service (starter) Create ***
BLEman started...
** Service (starter) Start **
BLEman StateChanged = 12
Error occurred on line: 15 (B4XPages)
java.lang.ClassCastException: java.lang.Object cannot be cast to FW6.App.b4xpagesmanager
    at FW6.App.b4xpages._getmanager(b4xpages.java:44)
    at FW6.App.b4xpages._mainpage(b4xpages.java:57)
    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:348)
    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.BleManager2$1$1.run(BleManager2.java:105)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6912)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
null: 59
java.lang.NullPointerException: Attempt to read from field 'java.lang.String anywheresoftware.b4a.shell.Shell$RemoteObject.className' on a null object reference
    at anywheresoftware.b4a.shell.Shell.getField(Shell.java:687)A note that the calls from Starter B4XPages.MainPage.DoDataAvailable( ServiceId, Characteristics ) works
as it did in the original example.
Sub BLEman_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double) also works well
as it did in the activity example it came from.
I just can't get the B4XPages.MainPage.StateChanged( State ) call back to work, won't run, crashes Java?
I added a parameter to StateChanged thinking that might be it? No change. Of the 3 call back functions
the two with parameters work, this one with out a parameter crashes java at runtime.
That's it, hope I'm clear on it. I'll attache the project files too.
Thanks in advance,
Marc