Java Question Error inflating androidx.fragment.app.FragmentContainerView

beachner

Member
I have a problem with a wrapper I'm trying to develop. It's for a mapping sdk that, I'm guesing, is using FragmentContainer internally.

I'm getting this error message:
error message:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 54 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:155)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at b4a.example.main._activity_create(main.java:397)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.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:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:147)
    ... 19 more
Caused by: android.view.InflateException: Binary XML file line #6 in b4a.example:layout/map_view: Binary XML file line #6 in b4a.example:layout/map_view: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #6 in b4a.example:layout/map_view: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Enum.ordinal()' on a null object reference
    at v.h.a(SourceFile:75)
    at l.b.a(SourceFile:178)
    at l.b.b(SourceFile:31)
    at l.c.onAttach(SourceFile:2)
    at androidx.fragment.app.Fragment.performAttach(Fragment.java:3063)
    at androidx.fragment.app.FragmentStateManager.attach(FragmentStateManager.java:464)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:254)
    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1899)
    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1823)
    at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1729)
    at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:323)
    at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.kt:158)
    at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:53)
    at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:136)
    at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:248)
    at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:227)
    at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1091)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1019)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:983)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1145)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1106)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:544)
    at k.k.a(SourceFile:1)
    at k.k.<init>(SourceFile:7)
    at com.mapfactor.sdk.map.MapView.<init>(SourceFile:2)
    at com.company.mapfactorwrapper.MapViewWrapper._initialize(MapViewWrapper.java:49)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:147)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at b4a.example.main._activity_create(main.java:397)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.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:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Message longer than Log limit (4000). Message was truncated.
** Activity (main) Resume **

The B4A testapp looks like this:

test app:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    #MultiDex: true
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalJar: com.google.android.material:material
    #AdditionalJar: androidx.appcompat:appcompat
    #AdditionalJar: androidx.appcompat:appcompat-resources
'    #AdditionalJar: androidx.fragment:fragment
    #AdditionalJar: kotlin-stdlib-1.6.10.jar
    #AdditionalJar: androidx.fragment:fragment-ktx
    #AdditionalJar:  androidx.collection:collection-ktx
    #AdditionalJar: androidx.arch.core:core-runtime
    #AdditionalJar: androidx.emoji2:emoji2
    #AdditionalJar: androidx.emoji2:emoji2-views-helper
    #AdditionalJar: androidx.emoji2:emoji2-views
    #AdditionalJar: androidx.emoji2:emoji2-bundled

#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #Extends: androidx.appcompat.app.AppCompatActivity
#End Region



Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Public mmpfcEngine As MpfcEngineWrapper
    Public rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'Private MapView1 As MapView

    
    
    Private MapView1 As MapView
    Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)

    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)

    Activity.LoadLayout("Layout")   
End Sub

Sub Activity_PermissionResult(Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION And Result = True Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim engine As JavaObject
        engine.InitializeNewInstance("com.company.mapfactorwrapper.MpfcEngineWrapper",Null)
        mmpfcEngine = engine
        Dim path = rp.GetAllSafeDirsExternal("")(0) As String
        mmpfcEngine.InitOSM(ctxt,path,mmpfcEngine.ENGLISH_US)
    End If
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub onEngineInitFinished_Fire(result As Int)
    xui.MsgboxAsync(result,"onEngineInitFinished")
    If result = mmpfcEngine.SUCCESS Then
    
    Else
        mmpfcEngine.ActivateDevice("<SDK Key>")
    End If
End Sub

Sub onEngineInitStatusChanged_Fire(result As Int)
        
End Sub

Sub onLocationPermissionNotGranted_Fire(permissionGranted As Boolean)
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

Sub onActivationResult_Fire(activationResult As Boolean)
    If activationResult = True Then
        xui.MsgboxAsync("Activation successful", "Failed")
    Else
        xui.MsgboxAsync("Failed activation ", "Failed")
        End If
End Sub

And the troublesome class in the wrapper looks likes this:

Map view wrapper:
package com.company.mapfactorwrapper;

import com.mapfactor.sdk.map.*;
import anywheresoftware.b4a.keywords.Common;
import anywheresoftware.b4a.objects.LabelWrapper;
import anywheresoftware.b4a.objects.PanelWrapper;
import anywheresoftware.b4a.objects.ViewWrapper;
import anywheresoftware.b4a.objects.collections.Map;
import anywheresoftware.b4a.BA;
import android.view.ViewGroup;


@BA.DependsOn(values = {"mpfc-sdk-2.1.0-production.aar"})
@BA.ShortName("MapView")
public class MapViewWrapper  extends ViewWrapper<MapView>  implements Common.DesignerCustomView   {

    private BA ba;
    private Map props;
    private String eventName;
    private static int id = 567472;
    private MapView mapView;
    
    public MapViewWrapper(){
        
    }
    
    public void addOnMapReadyListener(MapReadyListener listener) {
        ((MapView)this.getObject()).addOnMapReadyListener(listener);               
    }
    
    public MapFragment getMapFragment() {
        return ((MapView)this.getObject()).getMapFragment();
    }

    @Override
    public void DesignerCreateView(PanelWrapper base, LabelWrapper arg1, Map props) {
        this.props = props;
        
        ((ViewGroup)getObject()).setId(id);
        //((ViewGroup)getObject()).addView(mapView);
        
        
    }

    @Override
    public void _initialize(BA ba, Object arg1, String arg2) {
        this.ba = ba;       
        
         MapView mapView = new MapView(ba.context);
        
        this.setObject(mapView);
    }

    
}

Any ideas on how I can solve this problem?
 

beachner

Member
Maybe the activity must extend AppCompat or some other type of activity. Check the SDK documentation.
Good point but the activity is already extending from AppCompat and the documentation for FragmentContainerView doesn't specify enything else. And the example for the map sdk is using AppCompat
 

DonManfred

Expert
Licensed User
Longtime User
Post a link to the github project or the documentation of the sdk you want to implement.

Hard to help with guessing anything.
 

beachner

Member
I do have a key that has been successfully applied. The map engine appears to load successfully, at least according the device logs, but it won't render because it can't load the fragmentcontainerview resulting in a application crash
 

beachner

Member
No it was one of my colleagues that got the key. He knows Visual Basic and B4A but no Java or how to write a wrapper.
 

beachner

Member
Well, I've gotten around the problem. Sort of. Instead of using MapView I'm using MapFragment. The sdk loads and the application tries to render the map. The only problem now is that I get the same error inflating layout error but now instead it's about coordinatorlayout. So sort of progress.
 
Top