1. Are you ready for the Galaxy S20? Here is everything we know so far!

Camera X, LifecycleOwner ... "Cannot be cast to..."

Discussion in 'Android Development' started by Nightpoison, Aug 12, 2020.

  1. Nightpoison

    Nightpoison Newbie
    Thread Starter

    So I'm working with Camerax, new to Android development, and I'm attempting to write an application that takes an image on a specific event, not button related, without having to pull up the camera application. I have it all working, but my MainActivity is overloaded. So to clean up the MainActivity.java file I decided to offload different aspects to other files. Such as normal OOP concept.

    So I created a CameraFuncs.java file. Which I setup a constructor that I passed an object of the MainActivity class so I can access all the UI objects.

    Code (Java):
    1. public class CameraFuncs
    2. {
    3.     MainActivity main;
    5.     public CameraFuncs(MainActivity mainActivity)
    6.     {
    7.         main = mainActivity;
    8.   ...
    9.   ...
    10.   ...
    11.      }
    12. }
    my orientation listener works just fine. I have access to UI objects. Everything seems to be working just fine. Execpt when I attempt to bindtolifecycle(). It throws an error.

    Code (Java):
    1. Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector,
    2.                 main.imageCapture);
    I get the following error


    I'm not really understanding whats going on with bind to lifecycle. Can something clarify whats happening here, point me in the right direction?

    1. Download the Forums for Android™ app!



Share This Page