0

I have recently migrated code to support AndroidX and new versions of Xamarin.Forms ()Im trying to show a scanner activity which holds surface view in a linear layout, but it crashes on SetContentView, the Inner exception says - Binary XML file line #18 in com.dmi.ocuityaiqa:layout/select_dialog_multichoice_material: Error inflating class android.widget.CheckedTextView

  --- End of managed Android.Views.InflateException stack trace ---
android.view.InflateException: Binary XML file line #18 in com.dmi.ocuityaiqa:layout/select_dialog_multichoice_material: Error inflating class android.widget.CheckedTextView
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:858)
    at android.view.LayoutInflater.createView(LayoutInflater.java:780)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:934)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:954)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:533)
    at android.app.Activity.setContentView(Activity.java:3589)
    at crc6456e73fe34cc28457.ScanBarcodeActivity.n_onCreate(Native Method)
    at crc6456e73fe34cc28457.ScanBarcodeActivity.onCreate(ScanBarcodeActivity.java:45)
    at android.app.Activity.performCreate(Activity.java:8290)
    at android.app.Activity.performCreate(Activity.java:8270)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4009)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4201)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8663)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 17: TypedValue{t=0x2/d=0x7f030174 a=-1}
    at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:783)
    at android.view.View.<init>(View.java:5838)
    at android.widget.TextView.<init>(TextView.java:1264)
    at android.widget.CheckedTextView.<init>(CheckedTextView.java:102)
    at android.widget.CheckedTextView.<init>(CheckedTextView.java:98)
    at android.widget.CheckedTextView.<init>(CheckedTextView.java:94)
    ... 32 more

How to fix this I verified if supporting packages for AndroidX migration are added, everything is in place. Thank you!

Please Find Below Code -

[Activity(Label = "Scan Barcode/QR Code",Theme = "@style/MainTheme.Base")]
public class ScanBarcodeActivity : Activity, ISurfaceHolderCallback, IProcessor
{
    SurfaceView cameraPreview;
    CameraSource cameraSource;
    const int RequestCameraPermissionID = 1001;
    ScanType scanType;
    
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] AndroidContentPM.Permission[] grantResults)
    {
        switch (requestCode)
        {
            case RequestCameraPermissionID:
                {
                    if (grantResults[0] == AndroidContentPM.Permission.Granted)
                    {
                        if (ActivityCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted)
                        {
                            //Request permission
                            ActivityCompat.RequestPermissions(this, new string[]
                            {
                               Manifest.Permission.Camera
                            }, RequestCameraPermissionID);
                            return;
                        }
                        cameraSource.Start(cameraPreview.Holder);
                    }
                }
                break;
        }
    }

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        CrossScanningService.Current.ScanCompleted += Current_ScanCompleted;

        this.scanType = (ScanType)Enum.Parse(typeof(ScanType), Intent.GetStringExtra("ScanType"));

        this.Title = this.scanType == ScanType.Barcode ? "Scan Barcode or QR Code" : "Scan OCR";

        SetContentView(Resource.Layout.ScanBarcodeLayout);

        cameraPreview = FindViewById<SurfaceView>(Resource.Id.cameraPreview);
        var cancelButton = FindViewById<Button>(Resource.Id.cancelScanButton);
        cancelButton.Click += CancelButton_Click;

        switch (this.scanType)
        {
            case ScanType.Barcode:

                BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(this)
            .Build();

enter image description here

Waaheeda
  • 394
  • 3
  • 14
  • 1
    Could you provide some code related ? – Jianwei Sun - MSFT Sep 21 '22 at 08:50
  • @JianweiSun please check updated code in my question – Waaheeda Sep 21 '22 at 08:55
  • 1
    Where did you use `CheckedTextView` ? And check this [link](https://stackoverflow.com/questions/47157474/error-inflating-class-textview), it could give you some inspiration – Jianwei Sun - MSFT Sep 22 '22 at 05:58
  • @JianweiSun I have not used it anywhere , after setting AppCompact Theme for this activity , it stopped throwing InflateViewException but now its returning null for FindViewById – Waaheeda Sep 22 '22 at 06:02
  • `returning null for FindViewById` means that it couldn't find the view by Id(`Resource.Resource.Id.`). Check it to see if something go wrong. – Jianwei Sun - MSFT Sep 22 '22 at 06:09
  • @JianweiSun thanks for quick response ...I checked ids are correct its compiling but at Runtime im getting null for both surface view and button – Waaheeda Sep 22 '22 at 06:12
  • Is there something that is referenced from elsewhere in `surface view and button` ? Just like the situation described in this [link](https://stackoverflow.com/questions/47157474/error-inflating-class-textview) – Jianwei Sun - MSFT Sep 22 '22 at 06:33

0 Answers0