androidx.camera.view.PreviewView Causes java.lang.NullPointerException in Xamarin.Android Designer

Nathan Sokalski 4,111 Reputation points
2022-08-24T19:35:36.773+00:00

I am working on adding an androidx.camera.view.PreviewView to my Xamarin.Android app, but it displays a java.lang.NullPointerException in the Xamarin.Android Designer in Visual Studio 2022. The Details: displayed in the Designer are as follows:

android.hardware.display.DisplayManager.registerDisplayListener(DisplayManager.java:414)
androidx.camera.view.PreviewView.startListeningToDisplayChange(PreviewView.java:970)
androidx.camera.view.PreviewView.onAttachedToWindow(PreviewView.java:299)
android.view.View.dispatchAttachedToWindow(View.java:18347)
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:330)
com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:271)
mono.android.DesignerSession.loadInternal(DesignerSession.java:273)
mono.android.DesignerSession.lambda$load$0(DesignerSession.java:223)
mono.android.MonoDroidBroker.executeInMonoDroidContext(MonoDroidBroker.java:76)
mono.android.DesignerSession.load(DesignerSession.java:223)
mono.android.DesignerSession.processMessage(DesignerSession.java:676)
mono.android.MessageListener.executeMessage(MessageListener.java:88)
mono.android.MessageListener$Runner.run(MessageListener.java:44)
java.lang.Thread.run(Thread.java:748)

The exact xml of the PreviewView is as follows:

<androidx.camera.view.PreviewView android:id="@+id/pvCurrent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="0" tools:layout_width="match_parent" tools:layout_height="150dp" tools:background="@Color /Three"/>

I am not sure what to do, since this is my first time with PreviewView & it is a design time exception. What is the problem?

Developer technologies .NET Xamarin
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-08-25T07:55:17.597+00:00

    Hello,

    There is an official sample for how to use androidx.camera.view.PreviewView in Xamarin.Android, please refer to Xamarin.CameraX1.

    It's Xamarin.Android version to implement the official Google guide of Getting Started with CameraX.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.