Android Question java.lang.Exception / anywheresoftware.b4a.BA.raiseEvent2 (BA.java:227)

Marco Nissen

Active Member
Licensed User
Longtime User
Hi

on a few devices, I get this issue. I don't know what's wrong because for the majority of devices, the exception does not occur.
I am currently using B4A 12.50 and target is set to API 33 and device (pixel5 is also at 33)

Thanks
Marco

B4X:
Exception java.lang.Exception:
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:227)
  at anywheresoftware.b4a.keywords.Common$12$1.run (Common.java:1197)
  at anywheresoftware.b4a.BA.setActivityPaused (BA.java:467)
  at com.wurzelkraut.Stash2Go.main.afterFirstLayout (main.java:109)
  at com.wurzelkraut.Stash2Go.main.access$000 (main.java:17)
  at com.wurzelkraut.Stash2Go.main$WaitForLayout.run (main.java:83)
  at android.os.Handler.handleCallback (Handler.java:942)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8762)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:604)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

B4X:
private void afterFirstLayout() {
        if (this != mostCurrent)
            return;
        activityBA = new BA(this, layout, processBA, "com.wurzelkraut.Stash2Go", "com.wurzelkraut.Stash2Go.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
            if (isFirst)
                processBA.raiseEvent2(null, true, "SHELL", false);
            processBA.raiseEvent2(null, true, "CREATE", true, "com.wurzelkraut.Stash2Go.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
            _activity.reinitializeForShell(activityBA, "activity");
        }
        initializeProcessGlobals();       
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create " + (isFirst ? "(first time)" : "") + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
        isFirst = false;
        if (this != mostCurrent)
            return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
            try {
                android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
 
Last edited:

Marco Nissen

Active Member
Licensed User
Longtime User
timing wise that is true, and it might also that some piece of code interacts with the framework code, but again I was hoping to get some feedback from BA.java, and I didn't want to reverse engineer the APK to get some kind of java code that I could investigate in order to find the actual reason why.

interesting thing is, I have provided a test version, and that is running fine - I have re-structured some code, and more separated try/catch blocks and added display of progress messages via msgboxasync - will remove the latter and see if it still is OK and I accidentally fixed it. but still, would be great to get to know what the BA.java:227 is about
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I missed that line number. the Java code is
Java:
226      if (throwErrorIfMissingSub)
227        throw new Exception("Sub " + event + " was not found.");
It looks like raiseEvent2 is trying to run a non-existent Sub but the way it gets there is not just a simple call. It is invoked by setActivityPaused(false) running an instance of a RaiseEventWhenFirstCreate class which it finds from a list of messages called messagesDuringPaused which I can't trace back further. It's odd that the exception doesn't show that message with the Sub name so there is something else odd going on.
 
Upvote 0

Marco Nissen

Active Member
Licensed User
Longtime User
yes, you are right - I have two callsub calls in main, but those methods exist, and it should show the missing sub in the exception
 
Upvote 0
Top