Java Question B4J ba.raiseEventFromDifferentThread not working

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hello all ,

It could be a very simple problem but I have been searching forum and trying different ways to solve it for hours .
I am writing a wrapper for Twitter4J and it is working but I don't know how to call a sub .
The following will log
B4X:
From try: stream_update
What happened?java.lang.NullPointerException
And even without try block , sub is not called .
I changed getObject() to this and null without any success .
B4X:
        @Override
        public void onStatus(Status status) {
           
            try{
                ba.Log("From try: "+eventName + "_update" );
                ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_update" , false, new Object[] {status});
               
            }
             catch (Exception e){
                 ba.Log("What happened?"+e);
             }
           
        }
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
The sub is not called because there is an exception. You need to post the full stack trace from the logs.

Here is the log
B4X:
Program started.
[Tue Jun 21 10:11:22 AST 2016]Establishing connection.
[Tue Jun 21 10:11:24 AST 2016]Connection established.
[Tue Jun 21 10:11:24 AST 2016]Receiving status stream.
From try: stream_update
class java.lang.NullPointerException: null
    at smm.twitter4jp.TwitterStreamer$1.onStatus(TwitterStreamer.java:122)
    at twitter4j.StatusStreamImpl.onStatus(StatusStreamImpl.java:75)
    at twitter4j.StatusStreamBase$1.run(StatusStreamBase.java:105)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
This was indeed confusing. BA.Log is a static method so the object instance was not used.

The "correct" way to write it is:
B4X:
BA.Log("from try...
It was working with small letters that is also confusing .
Anyway thanks a lot for your usual great support :)
 
Top