Android Question AppCompat CreateMenu Error When Activity Paused

Kiran Raotole

Active Member
Licensed User
I used AppCompat Library for Activity Menu.
It works fine.
Recently I added GPS code in Actvity and app crash when GPS Location Setting Intent open
Logs :
Log:
** Activity (sale_order) Resume **
** Activity (sale_order) Pause, UserClosed = false **
Error occurred on line: 108 (sale_order)
java.lang.NullPointerException: Attempt to read from field '     com.ctron.mobile.sale_order.activityBA' on a null object reference
    at com.ctron.mobile.sale_order._activity_createmenu(sale_order.java:872)
    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:144)
    at com.ctron.mobile.sale_order._onCreateOptionsMenu(sale_order.java:5171)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.runHook(BA.java:165)
    at com.ctron.mobile.sale_order.onCreateOptionsMenu(sale_order.java:136)
    at android.app.Activity.onCreatePanelMenu(Activity.java:3481)
    at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:364)
    at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:93)
    at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:332)
    at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:93)
    at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:454)
    at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:55)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1004)
    at android.view.Choreographer.doCallbacks(Choreographer.java:816)
    at android.view.Choreographer.doFrame(Choreographer.java:748)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:990)
    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:6762)
    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:858)

Code :
CreateMenu:
Sub Activity_CreateMenu(Menu As ACMenu)
    Menu.Clear
    Dim item As ACMenuItem
    Dim bd As BitmapDrawable
    bd.Initialize(f1.TextToDrawable(Chr(0xE5C9),24))
    Menu.Add2(0,0,"Cancel Order",bd).ShowAsAction = item.SHOW_AS_ACTION_ALWAYS
End Sub

Location in Activity_Resume:
    Starter.GPS.Initialize("GPS")
    If Starter.GPS.GPSEnabled = False Then
        Msgbox("Location is off" & CRLF & "Enable Location",Starter.app_name)
        StartActivity(Starter.GPS.LocationSettingsIntent)
        Return
    Else
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
        Else
            MsgboxAsync("You not granted Permission","")
            Return
        End If
    End If

What should I do?
I try to use Sleep(0) in Activity_Resume and also in Activity_CreateMenu.
Didn't work.
 
Top