# CameraState.StateError

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/CameraState.java+class:androidx.camera.core.CameraState.StateError) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
@AutoValue
public abstract class CameraState.StateError
```

<br />

*** ** * ** ***

Error that the camera has encountered.

The camera may report an error when it's in one of the following states: `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPENING`, `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPEN`, `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSING` and `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSED`.

CameraX attempts to recover from certain errors it encounters when opening the camera device, in these instances, the error is `https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType#RECOVERABLE`, otherwise, the error is `https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType#CRITICAL`.

When CameraX encounters a critical error, the developer and/or user must intervene to restore camera function. When the error is recoverable, the developer and/or user can still aid in the recovery process, as shown in the following table.

| State | Error Code | Recoverable | How to handle it |
|---|---|---|---|
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPEN` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_STREAM_CONFIG()` | No | Make sure you set up your `https://developer.android.com/reference/androidx/camera/core/UseCase` correctly. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPENING` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_IN_USE()` | Yes | Close the camera, or ask the user to close another camera app that is using the camera. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPENING` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_MAX_CAMERAS_IN_USE()` | Yes | Close another open camera in the app, or ask the user to close another camera app that's using the camera. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#OPENING` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_OTHER_RECOVERABLE_ERROR()` | Yes | N/A |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSING` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_DISABLED()` | No | Ask the user to enable the device's cameras. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSING` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_FATAL_ERROR()` | No | Ask the user to reboot the device to restore camera function. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSED` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_DO_NOT_DISTURB_MODE_ENABLED()` | No | Ask the user to disable "Do Not Disturb" mode, then open the camera again. |
| `https://developer.android.com/reference/androidx/camera/core/CameraState.Type#CLOSED` | `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_REMOVED()` | No | The camera is offline. To use it again, the user must reconnect the device. The application should listen for the `onCameraAdded` event. |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#StateError()()` |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` | `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#create(int)(int error)` Creates a `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` with an error code. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` | `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#create(int,java.lang.Throwable)(int error, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Throwable.html cause)` Creates a `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` with an error code and a `https://developer.android.com/reference/java/lang/Throwable.html`. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Throwable.html` | `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#getCause()()` Returns a potential cause of this error. |
| `abstract int` | `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#getCode()()` Returns the code of this error. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType` | `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError#getType()()` Returns the type of this error. |

## Public constructors

### StateError

Added in 1.1.0

```
public StateError()
```

## Public methods

### create

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull CameraState.StateError create(int error)
```

Creates a `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` with an error code.

A `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` is not expected to be instantiated in normal operation.

### create

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public static @NonNull CameraState.StateError create(int error, @Nullable Throwable cause)
```

Creates a `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` with an error code and a `https://developer.android.com/reference/java/lang/Throwable.html`.

A `https://developer.android.com/reference/androidx/camera/core/CameraState.StateError` is not expected to be instantiated in normal operation.

### getCause

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public abstract @Nullable Throwable getCause()
```

Returns a potential cause of this error.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Throwable.html` | The cause of this error, or `null` if the cause was not supplied. |

### getCode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public abstract int getCode()
```

Returns the code of this error.

The error's code is one of the following: `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_IN_USE()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_MAX_CAMERAS_IN_USE()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_OTHER_RECOVERABLE_ERROR()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_STREAM_CONFIG()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_DISABLED()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_FATAL_ERROR()`, `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_DO_NOT_DISTURB_MODE_ENABLED()` and `https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_REMOVED()`.

| Returns |
|---|---|
| `int` | The code of this error. |

### getType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public @NonNull CameraState.ErrorType getType()
```

Returns the type of this error.

An error can either be `https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType#RECOVERABLE` or `https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType#CRITICAL`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraState.ErrorType` | The type of this error |