Java Question First Lib: Constructor not found

Zockolade

Member
Licensed User
Longtime User
Hi, I'm trying to create a Lib for Sygic Navi

https://www.b4x.com/android/forum/threads/accesing-sygic-sdk-with-additionaljar.80160/

Now I have created a first Lib with the SLC

First test:

B4X:
Dim Sygic As SygicApiControl
...
Sub Activity_Create(FirstTime As Boolean)
    ...
    Sygic.Initialize("com.sygic.truck", "com.sygic.truck.SygicService")
    ...
End Sub

When I call Sygic.Initialize I get this error:

B4X:
main_getsygicconnect (java line: 2541)

java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
    at mtrack.cartab.apk.main._getsygicconnect(main.java:2541)
    at mtrack.cartab.apk.main._activity_create(main.java:1529)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at mtrack.cartab.apk.main.afterFirstLayout(main.java:102)
    at mtrack.cartab.apk.main.access$000(main.java:17)
    at mtrack.cartab.apk.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6914)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
java.lang.RuntimeException: Constructor not found.

And this is my first java lib file. Where am I doing something wrong?


B4X:
package com.Sygic.ApiControl;

import com.sygic.sdk.remoteapi.Api;
import com.sygic.sdk.remoteapi.ApiCallback;
import com.sygic.sdk.remoteapi.ApiNavigation;
import com.sygic.sdk.remoteapi.events.ApiEvents;
import com.sygic.sdk.remoteapi.exception.NavigationException;


import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

// @Version(1.0)
@ShortName("SygicApiControl")
@ActivityObject

public class RemoteApiWrapper {
   
    private Api mApi = null;
    private boolean b;
   
    private ApiCallback mApiCallback = new ApiCallback() {

        @Override
        public void onServiceDisconnected() {
        }

        @Override
        public void onServiceConnected() {
            try {
                mApi.registerCallback();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onEvent(int event, String data) {
        }
    };
   
    public void Initialize(String SygicIdentificators,String SygicService) {
         mApi = Api.init(anywheresoftware.b4a.BA.applicationContext, SygicIdentificators, SygicService, mApiCallback);
     }   


}
 

Zockolade

Member
Licensed User
Longtime User
I had the JavaObject code unfortunately overlooked o_O it works now :)

How can I now access the callbacks (onServiceConnected...) in the b4a?
 

Zockolade

Member
Licensed User
Longtime User
Ok. I am now trying to implement the raiseEvent!!

The following error I get now:

B4X:
Starting step: Compiling Java code.
javac 1.8.0_05
C:\projekte_mask\Android\SimpleLibraryCompiler\SygicRemoteApi\src\anywheresoftware\b4a\objects\RemoteApiWrapper.java:70: error: non-static method raiseEvent(Object,String,Object...) cannot be referenced from a static context
                BA.raiseEvent(null,"sygic_onservicesonnected");               
                  ^
1 error


Error.

B4X:
    @Override
        public void onServiceConnected() {
       
            try {       
                BA.Log("** SygicWrapper: onServiceConnected ** ");   
                BA.raiseEvent(null,"sygic_onservicesonnected");               
                mApi.registerCallback();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
Top