Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NullPointer Exception error is happening in a small test on Android

Doing a little test on Android, writing this code in the backend:
enter image description here

And writing this code in the backend:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NullPointer Exception error is happening.
Can you please explain why, and how to fix?

>Solution :

Your Activity has no view upon object creation. Calling findByViewId before SetContentView will result in this problem.

setContentView(R.layout.activity_main);
//call after there is a view to get from.
test = findViewById(R.id.test);

As a future note please post code as text and not images or links, unless you need to show behavior that can’t be explained.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading