Skip to content
Advertisement

AndroidRuntime error at com.example.appname.MainActivity.onCreate

I am trying to write Java code that creates a button click event that populates an edit text box with my name. Unfortunately I am getting runtime errors. I checked almost all related topics and questions on stackoverflow but couldn’t figure it out my problem. Appreciated for your helps.

MainActivity.java

JavaScript

fragment_main.xml

JavaScript

AndroidManifest.xml

JavaScript

Error LogCat

JavaScript

Advertisement

Answer

Use fragment_main.xml instead of activity_main.xml for MainActivity layout because Button and EditText is in fragment_main with id’s by which you are trying to access in MainActivity :

JavaScript
Advertisement