Error:Uncaught translation error: com.android.dx.cf.code.SimException的一種情況
阿新 • • 發佈:2019-02-18
AndroidStudio 報的異常資訊
- Error:Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.
最近忙裡偷閒學習Kotlin,在我將一個專案裡的自定義View轉成kotlin程式碼時,沒有報錯,但是在編譯執行的時候這個異常就出現了,找了好久,stackoverflow上的都是和混淆有關的,和我這八竿子打不著,只能逐句程式碼debug下面是在編譯執行時期出現錯誤的程式碼
//這裡是用Kotlin外掛直接從Java程式碼轉到Kotlin的
//編譯執行時有錯
var leftx :Int
var rightx:Int
var mCurrentPageShadow: GradientDrawable
if (mIsRTandLB) {
leftx = mBezierControl1.x .toInt()
rightx = mBezierControl1.x.toInt() + 25
mCurrentPageShadow = mFrontShadowDrawableVLR
} else {
leftx = (mBezierControl1.x - 25).toInt()
rightx = mBezierControl1.x.toInt() + 1
mCurrentPageShadow = mFrontShadowDrawableVRL
}
正確姿勢
//這裡進行初始化
var leftx =0
var rightx=0
var mCurrentPageShadow: GradientDrawable
if (mIsRTandLB) {
leftx = mBezierControl1.x.toInt()
rightx = mBezierControl1.x.toInt() + 25
mCurrentPageShadow = mFrontShadowDrawableVLR
} else {
leftx = (mBezierControl1.x - 25).toInt()
rightx = mBezierControl1.x.toInt() + 1
mCurrentPageShadow = mFrontShadowDrawableVRL
}