我在Android Studio中制作应用程序并继续获取" java.lang.VerifyError"。它是在我用@Parcelize声明的类(Place Place)上传递一个包含Place对象的ArrayList。我知道它与自动生成的writeToParel(Parcel,Int)方法有关,但这与我能想出的所有方法有关。
我无法弄清楚为什么它会不断出现,我已经完成了以下建议的解决方案并且没有任何帮助:以下(类似SO帖子上提出的解决方案)不起作用:
我知道自动" parcelization"是一个实验性的功能,所以它可能只是一个错误 - 如果是这样,我可以尝试哪些变通方法?
从我创建的Place类创建对象时,错误开始。我复制了下面Place.kt,log和build.gralde的相关部分。提前致谢
Place.kt
@Parcelize
class Place constructor (var name:String, var placeID:String, var
description:String, var photoRef:String,
var price:Int, var rating:Int,
var location:Array<Double>) : Parcelable {
var googleURL : String
var lat : Double
var lng : Double
// Initialization instructions
init{
this.lat = location[0]
this.lng = location[1]
googleURL = makeGoogleMapsURL()
}
...
日志
06-18 15:55:19.174 5815-5815/com.example.daniel.digit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.daniel.digit, PID: 5815
java.lang.VerifyError: Verifier rejected class com.example.daniel.digit.Place: void com.example.daniel.digit.Place.writeToParcel(android.os.Parcel, int) failed to verify: void com.example.daniel.digit.Place.writeToParcel(android.os.Parcel, int): [0x48] register v3 has type Precise Reference: java.lang.Double but expected Double (Low Half) (declaration of 'com.example.daniel.digit.Place' appears in /data/app/com.example.daniel.digit-5DnxZcCKWzN_9Wj-TMpmIQ==/split_lib_slice_7_apk.apk)
at com.example.daniel.digit.MainActivity$onCreate$1.onClick(MainActivity.kt:79)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25883)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6642)
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:858)
摇篮
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
androidExtensions {
experimental = true
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.daniel.digit"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.beust:klaxon:3.0.1'
implementation "org.jetbrains.anko:anko:$anko_version"
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
答案 0 :(得分:0)
我不确定您班级的使用情况,但我发现错误提及了Double
所以我的推荐是:
Array<Double>
的{{1}},否则您可以使用:Double[]
转换为DoubleArray
(原始用法会让您的类更容易包裹)。还要尽量让你的课更简单。如果此类仅用于保存数据,则使用double[]
,如果需要所有数据,则可以从定义中删除单词data class
。