Bug? Is this crash a B4A bug or the DynamicGrid bug?

JohnC

Expert
Licensed User
Longtime User
In this post:

https://www.b4x.com/android/forum/threads/msdynamicgridview-library.49331/page-4#post-442520

A critical crash occurs and this is the line from the log:

java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA com.omnisoft.voiceit.main.activityBA' on a null object reference

Since the log line doesn't mention the dynamic grid, I was wondering if this error is "possibly' cause by something in B4A, or is it definitely caused by the grid I am using (when you consider the other entries in the log)?

If it helps determine the answer to my question, this is what I am thinking the problem is:

There are times when my app's main activity (the activity hosting the grid) could receive the focus (Activity_Resume), and immediately switch to a different activity. And I'm thinking that when the main activity got the focus, it caused a refresh/reload cycle of the grid control on it. But before the grid was able to go through and refresh all the items in it (the grid calls an event sub for each item), the main activity lost focus (because focus was transferred to the new activity) but the grid still tried invoke it's event, but it's host activity was not in a state to handle it because it didn't have the focus. So, what I think is happening is that the main activity looses focus before the grid control finished looping and invoke events for every item in the grid, and maybe that is causing this error/crash. But this is only a guess.
 

JohnC

Expert
Licensed User
Longtime User
OK, here is some very important info that should help give you an idea of the cause of this crashing:

B4A-DGCrash.png


As you can see, the crash happens AFTER the hosting activity (main) is paused.

So, why does it appear that the grid's sub event is being invoked (causing the null crash) after it's host activity is paused?

Is the grid suppose to check if it's hosting activity is active before invoking the event sub, or is B4A (or some other aspect of the OS) support to not let view events from being invoked after it's hosting activity is paused?
 

JohnC

Expert
Licensed User
Longtime User
This is a critical error that is holding me from releasing my app on the Play Store, so anything that you can do to help fix it would be greatly appreciated!

Here you go: (note: I made a small edit elsewhere in the code, which shifted the error line, but it's still the same line as you can see:

B4X:
803  Sub DA_GetContent(Position As Int, ItemID As Long, ItemTag As String, ContentPanel As Panel) As Panel

Also, you will see a lot of these steps in the log:

B4X:
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

Those are the steps that I repeated to reproduce the crash and it is random, but I can usually reproduce it in less then a dozen tries:

The Log you requested:

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
InAppBill.Init Time: 09:05:30
Audio Source: 1
Pos: 0 ItemID: 0 ItemTag: 1
DA_GetContent: ItemTag=1, DA.GetCount=25
Pos: 0 ItemID: 0 ItemTag: 1
DA_GetContent: ItemTag=1, DA.GetCount=25
Pos: 1 ItemID: 1 ItemTag: 2
DA_GetContent: ItemTag=2, DA.GetCount=25
Pos: 2 ItemID: 2 ItemTag: 3
DA_GetContent: ItemTag=3, DA.GetCount=25
Pos: 3 ItemID: 3 ItemTag: 4
DA_GetContent: ItemTag=4, DA.GetCount=25
Pos: 4 ItemID: 4 ItemTag: 5
DA_GetContent: ItemTag=5, DA.GetCount=25
Pos: 5 ItemID: 5 ItemTag: 6
DA_GetContent: ItemTag=6, DA.GetCount=25
Pos: 6 ItemID: 6 ItemTag: 7
DA_GetContent: ItemTag=7, DA.GetCount=25
Pos: 7 ItemID: 7 ItemTag: 8
DA_GetContent: ItemTag=8, DA.GetCount=25
Pos: 8 ItemID: 8 ItemTag: 9
DA_GetContent: ItemTag=9, DA.GetCount=25
Pos: 9 ItemID: 9 ItemTag: 10
DA_GetContent: ItemTag=10, DA.GetCount=25
Pos: 10 ItemID: 10 ItemTag: 11
DA_GetContent: ItemTag=11, DA.GetCount=25
Pos: 11 ItemID: 11 ItemTag: 12
DA_GetContent: ItemTag=12, DA.GetCount=25
Pos: 12 ItemID: 12 ItemTag: 13
DA_GetContent: ItemTag=13, DA.GetCount=25
Pos: 13 ItemID: 13 ItemTag: 14
DA_GetContent: ItemTag=14, DA.GetCount=25
Pos: 14 ItemID: 14 ItemTag: 15
DA_GetContent: ItemTag=15, DA.GetCount=25
Pos: 15 ItemID: 15 ItemTag: 16
DA_GetContent: ItemTag=16, DA.GetCount=25
Pos: 16 ItemID: 16 ItemTag: 17
DA_GetContent: ItemTag=17, DA.GetCount=25
Pos: 17 ItemID: 17 ItemTag: 18
DA_GetContent: ItemTag=18, DA.GetCount=25
Pos: 18 ItemID: 18 ItemTag: 19
DA_GetContent: ItemTag=19, DA.GetCount=25
Pos: 19 ItemID: 19 ItemTag: 20
DA_GetContent: ItemTag=20, DA.GetCount=25
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for com.omnisoft.voiceit
Subscriptions AVAILABLE.
** Activity (main) Resume **
InApp_BillingSupported Call: true, Setup successful. (response: 0:OK)
Time: 09:05:31
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: com.omnisoft.voiceit
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: com.omnisoft.voiceit
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
InAppBill_OwnedProducts Call: true
Time: 09:05:31
(MyMap) {}
ActionBar_MenuItemClick event fired, id:1
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = true **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
Pos: 0 ItemID: 0 ItemTag: 1
DA_GetContent: ItemTag=1, DA.GetCount=25
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
ActionBar_MenuItemClick event fired, id:1
No wakelock.
** Activity (main) Pause, UserClosed = false **
** Activity (comment) Create, isFirst = false **
** Activity (comment) Resume **
AB_Menu
** Activity (comment) Pause, UserClosed = true **
** Activity (main) Resume **
Pos: 0 ItemID: 0 ItemTag: 1
DA_GetContent: ItemTag=1, DA.GetCount=25
** Activity (main) Pause, UserClosed = false **
Error occurred on line: 803 (Main)
java.lang.NullPointerException
    at com.omnisoft.voiceit.main._da_getcontent(main.java:1629)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at com.maximussoft.gridviews.B4ADynamicGridAdapter.getView(B4ADynamicGridAdapter.java:66)
    at android.widget.AbsListView.obtainView(AbsListView.java:2597)
    at android.widget.GridView.onMeasure(GridView.java:1043)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChild(ViewGroup.java:4892)
    at android.view.ViewGroup.measureChildren(ViewGroup.java:4869)
    at anywheresoftware.b4a.BALayout.onMeasure(BALayout.java:64)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChild(ViewGroup.java:4892)
    at android.view.ViewGroup.measureChildren(ViewGroup.java:4869)
    at anywheresoftware.b4a.BALayout.onMeasure(BALayout.java:64)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2418)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2129)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1282)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1493)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1179)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4861)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    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:5293)
    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:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
    at android.widget.AbsListView.obtainView(AbsListView.java:2599)
    at android.widget.GridView.onMeasure(GridView.java:1043)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChild(ViewGroup.java:4892)
    at android.view.ViewGroup.measureChildren(ViewGroup.java:4869)
    at anywheresoftware.b4a.BALayout.onMeasure(BALayout.java:64)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChild(ViewGroup.java:4892)
    at android.view.ViewGroup.measureChildren(ViewGroup.java:4869)
    at anywheresoftware.b4a.BALayout.onMeasure(BALayout.java:64)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4921)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2418)
    at android.view.View.measure(View.java:16047)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2129)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1282)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1493)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1179)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4861)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    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:5293)
    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:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Hi Erel,

But, I have some comments/questions:

1) Since the line that it crashes on is the declare line for the event sub - I can't trap it, so it would be confusing how my code could cause this.
2) If an activity is paused, why can an event for a view on it be invoked? Who is the gate keeper? Is the grid suppose to check if it's hosting activity is active before invoking the event sub, or is B4A (or some other aspect of the OS) support to not let view events trigger after it's hosting activity is paused?
 

JohnC

Expert
Licensed User
Longtime User
...and also post the code in da_getcontent sub.

To elaborate on my #1 item above, if the error is happening on the declare line of the sub, then how could my code be the cause if it's not even being executed yet?
 

JohnC

Expert
Licensed User
Longtime User

JohnC

Expert
Licensed User
Longtime User
It doesn't look like a bug in B4A. It is either a bug in this library or in your code. Please start a new thread in the questions forum and also post the code in da_getcontent sub.

Hey Erel,

The author of the grid made this post:

https://www.b4x.com/android/forum/t...ter-parent-activity-paused.70436/#post-447834

Is there a chance that because the grid is using another thread, that the B4A event handling might be allowing the grid's event to trigger when the parent activity is paused?

I ask because one of the incoming parameters of the grid's event is a panel (ContentPanel as Panel), and that maybe the panel is null because the activity is paused?
 
Last edited:
Top