Android Question Problem with #AdditionalJar:, JavaObject and context

Discussion in 'Android Questions' started by lentunti, Jan 4, 2015.

Similar threads

B4A Code Snippet Change CheckBox colors
B4A Code Snippet Change EditText Colors
B4A Code Snippet Version safe notification
B4A Code Snippet Workaround the NetworkOnMainThread exception
B4A Tutorial Cards list with CustomListView
B4A Code Snippet Add pinned shortcut
  1. lentunti

    lentunti Member Licensed User

    Hi,

    I am using #AdditionalJar: and JavaObject to use an object in a jar file but I am having a problem creating the object with the context.

    The java code is this:-

    this.proConnectSdk = new ProConnectSdk(this.getApplicationContext());



    This error message happens
    java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:68)
    at b4a.example.main._getproconnect(main.java:432)
    at b4a.example.main._activity_create(main.java:319)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NoClassDefFoundError: com.tomtom.telematics.proconnectsdk.commons.AssertTool
    at com.tomtom.telematics.proconnectsdk.api.ProConnectSdk.<init>(ProConnectSdk.java:109)



    At this line of code

    Return jo.InitializeNewInstance("com.tomtom.telematics.proconnectsdk.api.ProConnectSdk", Array(context))

    The context JavaObject is an Application

    Here is my full code

    Region Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #End Region

    #Region Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #End Region
    #AdditionalJar: proconnectsdkapi

    Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    'proConnect.InitializeNewInstance("com.tomtom.telematics.proconnectsdk.api.ProConnectSdk", Null)

    End Sub

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.



    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")


    Dim Proconnect As JavaObject = GetProConnect

    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub GetContext As JavaObject
    Return GetBA.GetField("context")


    End Sub

    Sub GetBA As JavaObject
    Dim cls As String = Me
    Dim jo As JavaObject
    cls =cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
    End Sub

    Sub GetProConnect As JavaObject
    Dim jo As JavaObject
    Dim context As JavaObject = GetContext



    Return jo.InitializeNewInstance("com.tomtom.telematics.proconnectsdk.api.ProConnectSdk", Array(context))


    End Sub
     
    DavideV likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Seems like there is a class missing. Maybe you need to add another jar file.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice