No empty constructor when create a service

前端 未结 4 489
别跟我提以往
别跟我提以往 2020-12-01 08:40

I am struggling with this error:

08-08 11:42:53.179: E/AndroidRuntime(20288): Caused by: java.lang.InstantiationException: can\'t instantiate class co

4条回答
  •  长情又很酷
    2020-12-01 09:14

    If you have your Service declared as an Inner Class / Nested Class, you also need to make the class static

    Without that you´ll get the error even if your constructor is correct

    Explanation

    The reason for that is, you can only instantiate inner classes in the context of the outer class, so you would need to create an instance of the outer class first.

    Declaring your inner class static makes it independent from its outer class

提交回复
热议问题