Ernest Carmouche
Ernest Carmouche

Reputation: 1

Android Studio - App Preview shows the xml layout but when I run the App on Phone nothing shows up

I am trying to make a simple counter to test out what I've learned so far in Android. The xml seems to be right as it shows up just fine on the preview window but I think there is something off with the java as I can not get it on my phone, it is simply blank.

Here is the xml http://pastebin.com/G6Y4RFMb

Here is the Java http://pastebin.com/mNmT3bUJ

Thank you for your time. This is my first time posting so if I did anything wrong please let me know.

Upvotes: 0

Views: 347

Answers (2)

optimusfrenk
optimusfrenk

Reputation: 1321

You have to add this to the activity!

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.name_of_the_layout_file);
}

Maybe you just missed if not, this method is called by the system and is the right place to set up things. One of these things is the aspect of your activity.

P.S.: this is not Javascript, just Java.

Upvotes: 0

It is blank because you have not called your xml to work. Use something like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myxml);
}

Upvotes: 1

Related Questions