Android Question Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get() [SOLVED]

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I do this:
B4X:
Sub TellenUren(Controle As Boolean) As ResumableSub
    Wait For(Test(Controle)) Complete (Result As Int)
    Log("result: " & Result)
    Log("after sum")
    
    Return 0
End Sub


Sub Test(Para As Boolean) As ResumableSub
    If(Para) Then
        Return 1
    Else
        Return 0
    End If
End Sub

And I got this Crash:
B4X:
uren$ResumableSub_TellenUrenresume (java line: 4346)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
    at anywheresoftware.b4a.keywords.Common.WaitFor(Common.java:1834)
    at ciris.chauffeur.uren$ResumableSub_TellenUren.resume(uren.java:4346)
    at ciris.chauffeur.uren._tellenuren(uren.java:4322)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1167)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1122)
    at ciris.chauffeur.uren$ResumableSub_HeenVT_FocusChanged.resume(uren.java:2699)
    at ciris.chauffeur.uren._heenvt_focuschanged(uren.java:2627)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA$1.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:1001)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loopOnce(Looper.java:268)
    at android.os.Looper.loop(Looper.java:384)
    at android.app.ActivityThread.main(ActivityThread.java:8936)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:907)

I use this to start:
B4X:
Wait For (CallSub2(Me,"TellenUren",False)) Complete (dummy As Object)

What can be wrong?

Kind regards,
André
 
Solution
Hi William and others,

The problem seems to be solved by rebuilding the part of my app. The cause could be a StringToNumber conversie on a empty string on a seperate Sub, but not sure about this.

It is working now. Thanks for helping.

Kind regards,
André

AHilberink

Active Member
Licensed User
Longtime User
I changed your Wait For statement. Then it works as expected.
B4X:
    Wait For (TellenUren(False)) Complete (dummy As Object)

Hi William,

Thank you for your reply. Unfortunally I still got the same crash after changing the Wait For. Is there something else I can check?

Kind regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi William,

Thank you for your reply. Unfortunally I still got the same crash after changing the Wait For. Is there something else I can check?

Kind regards,
André

Hi Again,

I tested it with a new, small progamm and it worked as expected. Donn't know why. I will try to find the cause by rebuilding that part of my App.

Kind regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi William and others,

The problem seems to be solved by rebuilding the part of my app. The cause could be a StringToNumber conversie on a empty string on a seperate Sub, but not sure about this.

It is working now. Thanks for helping.

Kind regards,
André
 
Upvote 0
Solution

William Lancee

Well-Known Member
Licensed User
Longtime User
I am a few hours later here in Canada, so I just started looking at this.
Since I had tested your small example myself and it worked, my suggestion would have been to look
in other parts of your code for the source of the error. But I see you found a solution (if not the actual bug:)).
 
Upvote 0
Top