Kotlin - 未解决的常量引用
Kotlin - unresolved reference for constant
我正在尝试将新相机硬件 API (android.hardware.camera2) 的示例代码用于我的 android 应用程序。首先,我通过 Android Studio 的 Kotlin 插件的自动转换功能将 Java 代码转换为 Kotlin 代码。下面是一段转换后的代码:
private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() {
private fun process(result: CaptureResult) {
when (mState) {
STATE_PREVIEW -> {
}// We have nothing to do when the camera preview is working normally.
STATE_WAITING_LOCK -> {
val afState = result.get(CaptureResult.CONTROL_AF_STATE)
if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
mState = STATE_WAITING_NON_PRECAPTURE
captureStillPicture()
} else {
runPrecaptureSequence()
}
}
}
STATE_WAITING_PRECAPTURE -> {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_NON_PRECAPTURE
}
}
STATE_WAITING_NON_PRECAPTURE -> {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
mState = STATE_PICTURE_TAKEN
captureStillPicture()
}
}
}
}
我收到未解决的参考错误:
CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED
CaptureResult.CONTROL_AE_STATE_CONVERGED
CaptureResult.CONTROL_AE_STATE_PRECAPTURE
CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
但是这些常量在原来的Java代码中是可以识别的。这些错误有什么解决方案吗?
这些变量在 CameraMetadata 中声明。在 Kotlin 中,静态变量和方法不能在子类上调用。
我正在尝试将新相机硬件 API (android.hardware.camera2) 的示例代码用于我的 android 应用程序。首先,我通过 Android Studio 的 Kotlin 插件的自动转换功能将 Java 代码转换为 Kotlin 代码。下面是一段转换后的代码:
private val mCaptureCallback = object : CameraCaptureSession.CaptureCallback() {
private fun process(result: CaptureResult) {
when (mState) {
STATE_PREVIEW -> {
}// We have nothing to do when the camera preview is working normally.
STATE_WAITING_LOCK -> {
val afState = result.get(CaptureResult.CONTROL_AF_STATE)
if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState || CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
mState = STATE_WAITING_NON_PRECAPTURE
captureStillPicture()
} else {
runPrecaptureSequence()
}
}
}
STATE_WAITING_PRECAPTURE -> {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_NON_PRECAPTURE
}
}
STATE_WAITING_NON_PRECAPTURE -> {
// CONTROL_AE_STATE can be null on some devices
val aeState = result.get<Int>(CaptureResult.CONTROL_AE_STATE)
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
mState = STATE_PICTURE_TAKEN
captureStillPicture()
}
}
}
}
我收到未解决的参考错误:
CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED
CaptureResult.CONTROL_AE_STATE_CONVERGED
CaptureResult.CONTROL_AE_STATE_PRECAPTURE
CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
但是这些常量在原来的Java代码中是可以识别的。这些错误有什么解决方案吗?
这些变量在 CameraMetadata 中声明。在 Kotlin 中,静态变量和方法不能在子类上调用。