读取二维码会使 kotlin 应用程序崩溃
Reading QR Code crashes kotlin application
我正在尝试使用 Kotlin 创建二维码扫描器。这是我目前的代码
这是我的 gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.google.codelabs.mdc.kotlin.shrine"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// barcode scanning
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
这就是我所说的扫描
val clickListener = View.OnClickListener { view ->
when(view.id) {
R.id.button_class1 -> textView_class.text = "1"
R.id.button_class2 -> textView_class.text = "2"
R.id.button_class3 -> textView_class.text = "3"
R.id.button_scan -> {
val scanner = IntentIntegrator(this.activity)
scanner.initiateScan()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(resultCode == Activity.RESULT_OK) {
var result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (result != null) {
if (result.contents == null) {
Toast.makeText(context, "CANCELED", Toast.LENGTH_SHORT)
} else {
println("QR CODE ${result.contents}")
}
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}
}
当我点击我的 button_scan 时,我暂时能够非常非常短暂地进入扫描部分,然后它因以下错误而崩溃:
2020-03-20 16:05:40.280 29202-29202/? E/Zygote: isWhitelistProcess - Process is Whitelisted 2020-03-20 16:05:40.281 29202-29202/? E/Zygote: accessInfo : 1 2020-03-20 16:05:40.309 29202-29202/? E/c.kotlin.shrin: Unknown bits set in runtime_flags: 0x8000 2020-03-20 16:05:44.973 29202-29202/com.google.codelabs.mdc.kotlin.shrine E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.codelabs.mdc.kotlin.shrine, PID: 29202
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at com.journeyapps.barcodescanner.CaptureManager.<init>(CaptureManager.java:130)
at com.journeyapps.barcodescanner.CaptureActivity.onCreate(CaptureActivity.java:23)
at android.app.Activity.performCreate(Activity.java:7981)
at android.app.Activity.performCreate(Activity.java:7970)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7777)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
你能告诉我如何更正这个吗?
尝试切换到 Java 8 兼容性,某些库要求:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
我正在尝试使用 Kotlin 创建二维码扫描器。这是我目前的代码
这是我的 gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.google.codelabs.mdc.kotlin.shrine"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// barcode scanning
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
这就是我所说的扫描
val clickListener = View.OnClickListener { view ->
when(view.id) {
R.id.button_class1 -> textView_class.text = "1"
R.id.button_class2 -> textView_class.text = "2"
R.id.button_class3 -> textView_class.text = "3"
R.id.button_scan -> {
val scanner = IntentIntegrator(this.activity)
scanner.initiateScan()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(resultCode == Activity.RESULT_OK) {
var result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
if (result != null) {
if (result.contents == null) {
Toast.makeText(context, "CANCELED", Toast.LENGTH_SHORT)
} else {
println("QR CODE ${result.contents}")
}
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}
}
当我点击我的 button_scan 时,我暂时能够非常非常短暂地进入扫描部分,然后它因以下错误而崩溃:
2020-03-20 16:05:40.280 29202-29202/? E/Zygote: isWhitelistProcess - Process is Whitelisted 2020-03-20 16:05:40.281 29202-29202/? E/Zygote: accessInfo : 1 2020-03-20 16:05:40.309 29202-29202/? E/c.kotlin.shrin: Unknown bits set in runtime_flags: 0x8000 2020-03-20 16:05:44.973 29202-29202/com.google.codelabs.mdc.kotlin.shrine E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.codelabs.mdc.kotlin.shrine, PID: 29202
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
at com.journeyapps.barcodescanner.CaptureManager.<init>(CaptureManager.java:130)
at com.journeyapps.barcodescanner.CaptureActivity.onCreate(CaptureActivity.java:23)
at android.app.Activity.performCreate(Activity.java:7981)
at android.app.Activity.performCreate(Activity.java:7970)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3594)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7777)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
你能告诉我如何更正这个吗?
尝试切换到 Java 8 兼容性,某些库要求:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}