如果代码中存在java.util.Calendar.getInstance(),则应用程序在即时运行后崩溃

时间:2019-02-07 13:32:28

标签: android android-studio kotlin

在代码中添加val x = java.util.Calendar.getInstance().time后,当我调用包含Calendar变量的类时,尝试在Android Studio中应用即时更改(Ctrl + F10)时,应用程序崩溃。

奇怪的是,它可以通过停止并再次运行应用程序来工作,问题似乎仅在即时运行时仍然存在。

这是崩溃后的错误堆栈跟踪

D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: uk.co.projectnamespace.firstapp, PID: 24380
    java.lang.IllegalAccessError: Illegal class access: 'uk.co.projectnamespace.firstapp.service.FirstAppDAOFirebaseImpl$override' attempting to access 'kotlin.jvm.internal.DefaultConstructorMarker' (declaration of 'uk.co.projectnamespace.firstapp.service.FirstAppDAOFirebaseImpl$override' appears in /data/data/uk.co.projectnamespace.firstapp/files/instant-run/dex-temp/reload0x0000.dex)
        at uk.co.projectnamespace.firstapp.service.FirstAppDAOFirebaseImpl$override.saveDonationMaster(FirstAppDAOFirebaseImpl.kt:95)
        at uk.co.projectnamespace.firstapp.service.FirstAppDAOFirebaseImpl$override.saveDonation(FirstAppDAOFirebaseImpl.kt:43)

有人遇到过类似的问题,有没有解决的办法?

谢谢!

1 个答案:

答案 0 :(得分:0)

Its working fine 

import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.example.smartclient.R


class MainK : AppCompatActivity()
{

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        setContentView(R.layout.activity_login)
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onResume() {
        super.onResume()

        val x = java.util.Calendar.getInstance().time

        System.out.print(x)
        Toast.makeText(this,"Time: "+x,Toast.LENGTH_LONG).show()
    }
}