0

I am currently testing androidx.camera.view.CameraView, but when I use it with ConstraintLayout (also happens with FrameLayout) it raises a Render Problem.

The versions of CameraX libaries I am using are: androidx.camera:camera-core:1.0.0-alpha06 androidx.camera:camera-camera2:1.0.0-alpha06, androidx.camera:camera-view:1.0.0-alpha03 and androidx.camera:camera-extensions:1.0.0-alpha03.

The following is my layout file:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

<data>
    <variable name="recordedDetectionViewModel"
              type="com.biolab.plr.screens.recorded.RecordedDetectionViewModel"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".screens.recorded.RecordedDetectionFragment">

    <TextView
            android:id="@+id/fpsTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/cameraView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent"
            android:text="@{@string/fps(recordedDetectionViewModel.fps)}"
    />

    <androidx.camera.view.CameraView
            app:layout_constraintTop_toBottomOf="@+id/fpsTextView"
            app:layout_constraintBottom_toTopOf="@+id/recordButton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:id="@+id/cameraView"
            android:layout_width="0dp"
            android:layout_height="0dp"/>

    <Button
            android:id="@+id/recordButton"
            android:text="@{recordedDetectionViewModel.buttonText}"
            android:onClick="@{() -> recordedDetectionViewModel.onRecordButtonClicked()}"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="32dp"
            app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

This is the stack trace following the Render Error:

java.lang.NullPointerException
at android.hardware.display.DisplayManager.registerDisplayListener(DisplayManager.java:414)
at androidx.camera.view.CameraView.onAttachedToWindow(CameraView.java:328)
at android.view.View.dispatchAttachedToWindow(View.java:18347)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3397)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:330)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:200)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:572)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:698)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
herculanodavi
  • 228
  • 2
  • 12

0 Answers0