开发者

Simple hello world for Android app won't display text

开发者 https://www.devze.com 2023-04-03 18:01 出处:网络
I recently bought an Android phone and am trying to learn to code my own apps. Unfortunately after the first ten seconds I ran into the problem where I can\'t even get the \"hello world\" tutorial to

I recently bought an Android phone and am trying to learn to code my own apps. Unfortunately after the first ten seconds I ran into the problem where I can't even get the "hello world" tutorial to display "hello world."

I've read similar posts and I can't seem to find a fix. Since the Android loading logo is displaying I've waited for about ten minutes thinking it was just taking a while for the emulator to boot, but no luck.

package multivax.random;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class RandomNumbersActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstan开发者_开发百科ceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello World");
        this.setContentView(tv);
    }
}


do not close the emulator once you have turned it on. just recompile it and send it to the already open emulator.

why are you saying this.setContentView(tv); instead of just setContentView(tv); ?

and by the way check you xml file to make sure that this is the main activity (i.e. the activity that starts when your application starts)


this.setContentView(tv) is also equals setContentView(tv), there have no problem. also right Android code. You only can find something by adb logcat,you will find some usable information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号