Android Question [SOLVED] Please Help: error with ba.startActivityForResult(ion, null) on B4A 11.50

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
After the latest B4a installation (11.50) my code give an uncommon error message:
Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
Here is my code:
B4X:
     ion = new IOnActivityResult() {
            @Override
            public void ResultArrived(int resultCode, Intent data) {
                pResultArrived("payment", resultCode, data);
            }
        };
    try {
         ba.startActivityForResult(ion, null); //<-- passing null instead of an intent (as in official code)
    } catch (NullPointerException npe) {
         //
         BA.Log("ion "+npe.getMessage());
    }
This code snippet worked extremly well before B4A 11.50 !!
Can you help me please?
 

DonManfred

Expert
Licensed User
Longtime User
method 'boolean android.content.Intent.migrateExtraStreamToClipData()
where does this come from if you do not use any intent?

Incomplete/wrong code posted?
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Dear DonManfred,
It is the perfect, relevant code. The point is that it worked perfectly fine before version 11.50 and now the same code, without any changes, does not work. But here is the more complete code:

B4X:
public void payment(BA ba,double ossz,String uuid, int commrec, int custrec) {
//custrec / commrec: 1:ON,2:OFF,3:CONFIRMATION
int requestCode;
xba = ba;
try {
// Build the payment call
    MyPOSPayment payment = MyPOSPayment.builder()
         .productAmount(ossz)
         .currency(Currency.HUF)
         .foreignTransactionId(uuid)
     .reference(uuid, ReferenceType.REFERENCE_NUMBER)
     .printMerchantReceipt(commrec)
     .printCustomerReceipt(custrec)
     .fixedPinpad(true)
         .build();
     ion = new IOnActivityResult() {
            @Override
            public void ResultArrived(int resultCode, Intent data) {
                pResultArrived("payment", resultCode, data);
            }
        };
    try {
         ba.startActivityForResult(ion, null); //<-- passing null instead of an intent
    } catch (NullPointerException npe) {
         BA.Log("ion "+npe.getMessage()); '<<-- exception here
    }
    BA.SharedProcessBA sba = ba.sharedProcessBA;
    try {
         Field f = BA.SharedProcessBA.class.getDeclaredField("onActivityResultCode");
         f.setAccessible(true);
         requestCode = f.getInt(sba) - 1;
    } catch (Exception e) {
         BA.Log("reqc "+e.getMessage());
         throw new RuntimeException(e);
    }
    MyPOSAPI.openPaymentActivity(ba.activity, payment, requestCode);
    } catch (Exception e) {
        callResultProc( "payment", false, "Error " + e.getMessage());
    }
}
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
It's probably not B4A 11.50 that is the problem but that you are probably targeting SDK 30 with its increased security measuses. You could see if setting target SDK to 28 works and then if you need to target SDK 30 try add inga <queries> item to your manifest See this thread post #4 onwards.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
It's probably not B4A 11.50 that is the problem but that you are probably targeting SDK 30 with its increased security measuses. You could see if setting target SDK to 28 works and then if you need to target SDK 30 try add inga <queries> item to your manifest See this thread post #4 onwards.
Thank you Agraham, I tried both thing: targeting sdk 28 and queries too
B4X:
AddManifestText(
<queries>
        <package android:name="com.mypos.smartsdk" />
</queries>
)
but the result is the same. Now I try to make a tiny test app, whether I see somenthing more.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Yet I think about that in the 11.50 version something changed, because one of my app that was lastly compiled by 11.20 at 16 March and I have its compiled apk that works.
I have all source code also and when I compile it by 11.50 version, my app shows error.
Contrary to this, if I install B4A version 11.20 on a virtual machine, I can't compile a working app (with original source files), although I haven't original c:\android folder because I updated today and I don't have a backup of the March 16th version.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I have a stack trace:
B4X:
ion Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1698)
    at android.app.Activity.startActivityForResult(Activity.java:6066)
    at android.app.Activity.startActivityForResult(Activity.java:6024)
    at anywheresoftware.b4a.BA.startActivityForResult(BA.java:559)
    at b4a.mp.myposclass.payment(myposclass.java:1064)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4a.mp.myposclass._payment(myposclass.java:197)
    at b4a.mp.main$ResumableSub_fizetes.resume(main.java:422)
    at b4a.mp.main._fizetes(main.java:376)
    at b4a.mp.main._button1_click(main.java:370)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6608)
    at android.view.View.performClickInternal(View.java:6585)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25965)
    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:6865)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
payment_result event found
Payment_result false
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Investigate further, my exception happens here:
B4X:
MyPOSAPI.openPaymentActivity(ba.activity, payment, requestCode);

ooops, my ba.activity is null.

the ba isn't null, it is anywheresoftware.b4a.ShellBA@1612bbc
 
Last edited:
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
@Spavlyuk , you are genius!

once upon a time I did, but for some reason I reached into the class and took out this line because I couldn't remember what it was there for, and with that I couldn't put my class declaration in process_global. I was stupid.
 
Upvote 0
Top