Call B4A Funktions in a Class

kkolle

Member
Licensed User
Longtime User
Hi,
Sometimes i have a problem to call StartActivity or CallSubDelayed2 from my Class.

In my "Main" Activity_Create i Initialize my Class.

I have a Funkton thet calls StartActivity(myActiviti) and it works, but sometimes i get NullPointerException when StartActivity(myActiviti) called

Sombody an idea?

For Example like this code:

B4X:
'Main
Sub Globals
 Dim myStops As CStops

end Sub

Sub Activity_Create
 myStops.Initialize
end Sub

Sub DoSomething
 myStops.DoThings
end Sub


B4X:
'class CStops

Sub DoThings
 'some Code...
 'some Code...
 'some Code...
'open Activity get sometimes NullPointerException 
 StartActivity(myActiviti) 
end Sub
 
Last edited:

kkolle

Member
Licensed User
Longtime User
stack trace

Hallo Erel,

thank you for answer. Here is the stack trace

cstops_finishstop (java line: 145)
java.lang.NullPointerException
at anywheresoftware.b4a.B4AClass.getActivityBA(B4AClass.java:16)
at com.mo.msm.cstops._finishstop(cstops.java:145)
at com.mo.msm.main._qacactivestop_click(main.java:2203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at de.amberhome.quickaction.QuickAction3D$1.onItemClick(QuickAction3D.java:90)
at de.amberhome.quickaction.QuickAction3D$3.onClick(QuickAction3D.java:191)
at android.view.View.performClick(View.java:4202)
at android.view.View$PerformClick.run(View.java:17340)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
 
Upvote 0

kkolle

Member
Licensed User
Longtime User
Hallo Erel,

in my App i call a funkton in a main Activity as follow:

I send you my real code ACTEquipmentList is an Activity Modul

B4X:
' call in Main
Sub qacActiveStop_Click (Position As Int, ActionItemID As Int)
 Select Database.GetActiveStopState(Database.GetActiveStopId)
   Case BuildConfig.OrderStatus.Started
      SetActiveStopState(BuildConfig.OrderStatus.Arrived)
   Case BuildConfig.OrderStatus.Arrived
           'here i call the funktion FinishStop from a class Stops 
           myStops.FinishStop(Database.GetActiveStopId, Database.mySQL)
 End Select
End Sub

B4X:
'Class Stops: funkton FinishStop
Sub FinishStop(StopId As String, mySQL As SQL)
   If BuildConfig.CurrentBuildConfiguration = BuildConfig.BuildConfiguration.MSM Then
      Dim modulName As String
      Dim suppMustFill As Boolean
      Dim Cursor As Cursor
      modulName = GetModulByFinishOrder(StopId, mySQL)
      If modulName.Length > 0 Then
         Select modulName
            Case "16"
               ACTEquipmentList.SelectedStopId = StopId
                                        'out here is th stack trace (from this call)
               StartActivity(ACTEquipmentList)
               SetFinishState(StopId, "16", "1", mySQL)
               Return
            Case "10"
            
         End Select
      End If

      suppMustFill = GetSuppMustFill(StopId, mySQL)
      If suppMustFill = True Then
         Return
      End If
      If CheckSig(StopId, mySQL) = False Then
         SetActiveStopState(BuildConfig.OrderStatus.Ready)
      Else

         ACTSignature.Context = "STOP"
         StartActivity(ACTSignature)
      End If
   Else 
         SetActiveStopState(BuildConfig.OrderStatus.Ready)
   End If
End Sub
 
Last edited:
Upvote 0

kkolle

Member
Licensed User
Longtime User
I am sorry Erel but I can't upload a complete Project.

The Problem is, sometimes when i call StartActivity(ACTEquipmentList) or StartActivity(ACTSignature), i get the Exception you can see in the stack trace.

ACTEquipmentList is an Activity that include a list of items to select one of them.

ACTSignature is an Activity to get signatures

cstops_finishstop (java line: 145) the line in java file -> c.StartActivity(getActivityBA(),(Object)(_actequipmentlist.getObject()));
 
Upvote 0

kkolle

Member
Licensed User
Longtime User
Hallo Erel

here my initializing in steps:

B4X:
'Main  Activity
Sub Globals
 ...
 Dim myStops As CStops
 ...
End Sub

Sub Activity_Create(FirstTime As Boolean)
 ...
 myStops.Initialize
 ...
End Sub
 
Upvote 0

kkolle

Member
Licensed User
Longtime User
Hi,

I solved the Problem. The problem was initializing in Activity_Create. If Activity_Create was called second time (for example rotate the device) i get the exception.
 
Upvote 0
Top