2021年4月1日星期四

Android Studio - setContentView Wont Display New XML Layout

Very New to Android Studio and I am following a simple Udemy tutorial. I have:

  1. Successfully created a main.xml file
  2. Successfully utilized the file in the code: setContentView(R.layout.main);

Per the tutorial, I created a second xml file, with just a simple button, named "test.xml". I followed the instructions to utilize it in the setContentView:

setContentView(R.layout.test);

However, every time I run the emulator after the change nothing happens - I get a white screen that quickly closes, the app does not open. In the Run section I get the message "Success Operation succeeded." The build section states "finished."

If I repeatedly replay the app I get a message in the emulator that states: "App name keeps stopping" but no real info beyond that.

I think I'm creating the new xml file correctly: In the res folder -> File New -> Android Resource File -> Give it a file name (e.g. test). The new xml file then falls into the layout folder in my res folder.

I've created a number of xml files and I always get the same result. I don't see anywhere showing me an error.

I'm at lost for what I'm doing wrong in such a simple exercise.

https://stackoverflow.com/questions/66913313/android-studio-setcontentview-wont-display-new-xml-layout April 02, 2021 at 09:08AM

没有评论:

发表评论