Search code examples
androidandroid-activityandroid-contextmobile-devices

Why Some devices doesn't work with 'startActivity(this, MainActivity:class.java)'?


related question: startActivity(intent) doesn't work in some devices

I tested out with LUNA(5.0.2) from TG&CO and Galaxy J5 2016(6.0.1) from SAMSUNG, PHAB 2 PRO from LENOVO, SKY IM-100 from Pantech.

They doesn't work with

startActivity(this, MainActivity::class.java)
startActivity(this@SplashActivity, MainActivity::class.java)

I guess a lot of things related to context. This shows this error:

java.lang.NoClassDefFoundError: com.example.view.main.MainActivity

Try-catch doesn't work either. I tested more than 20 devices. And only those devices have the problem.

What's wrong with the devices?


Solution

  • Well, It happened because of I used some Interfaces but didn't implement them completely. It had a red line at the first line of the class. I don't know how it is able to build the project. Anyway, It built the project perfectly and worked fine with popular phones. But didn't work with the phones that I mentioned above.

    After fixing this problem, All the phones worked fine. If you know the reason why they work like this, Please comment.