Android Question How To Call Jar Public Synchronized Method

Richard Goh

Active Member
Licensed User
Longtime User
Hi,

I have a jar file and contain below methods. I managed to initialize the class with below program code
. But when I try to call the start() method but it's prompt error in log (java.lang.IllegalArgumentException: expected receiver of type driver.Printer, but got java.lang.Class<driver.Printer>). How do I call a public synchronized methods?

My program code
B4X:
Dim jo As JavaObject
jo.InitializeStatic("driver.Printer").RunMethod("getInstance", Null)
jo.RunMethodJO("start", Null)

.Jar Methods
B4X:
    public static Printer getInstance() {
        if(mprinter == null) {
            mprinter = new Printer();
        }
        return Printer;
    }

    public void setHandler(Handler handler) {
        this.mHandler = handler;
    }

    public synchronized void start() {
        if(this.mConnectThread != null) {
                 this.mConnectThread.cancel();
                 this.mConnectThread = null;
         }

         if(this.mConnectedThread != null) {
             this.mConnectedThread.cancel();
             this.mConnectedThread = null;
         }

         if(this.mAcceptThread == null) {
                 this.mAcceptThread = new HsBluetoothPrintDriver.AcceptThread();
                 this.mAcceptThread.start();
         }

         this.setState(1);
}

Btw, how do I initialize or use Interface class in B4A like show below?

.Jar interface class
B4X:
public interface Contants {
    boolean DEBUG = false;
    int UNCONNECTED = 16;
    int CONNECTED_BY_BLUETOOTH = 17;
    int CONNECTED_BY_USB = 18;
    int CONNECTED_BY_WIFI = 19;
    int FLAG_STATE_CHANGE = 32;
    int FLAG_FAIL_CONNECT = 33;
    int FLAG_SUCCESS_CONNECT = 34;
    int FLAG_MSG_READ = 35;
    int TYPE_58 = 0;
    int TYPE_80 = 1;
}
 
Top