+ Reply to Thread
Results 1 to 8 of 8

Thread: Beginner's Hello World, need help ...

  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Default Beginner's Hello World, need help ...


    Hi,

    I have followed the android hello world example, I followed exactly
    all the steps, but got a different result.

    According to the example, the result should be a window with the title
    of "Hello, Android", and the content of "Hello, Android" as well. But
    what I got is a title "Hello, Android" and the content of "Hello
    World, HelloAndroid". I tried to put other strings in tv.setText(),
    but it never shows up. looks like the content of the window is always
    the class name following "Hello World," but where the hell does the
    "Hello World" string comes from? There's only a "Hello Android" in the
    java code.

    Help is highly appreciated.

    Here is the code:
    <code>
    package com.google.android.hello;

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

    public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    TextView tv = new TextView(this);
    tv.setText("Hello, Android");
    setContentView(R.layout.main);
    }
    }

    </code>

    Hua Yanghao

  2. #2
    Join Date
    Dec 2007
    Posts
    4

    Default

    I think you should setContentView to tv not R.layout.main.

    My problem is when i run the application, the emulator starts, but nothing is displayed.. who can help?

  3. #3
    Join Date
    Dec 2007
    Posts
    5

    Default

    jandfus is correct. The problem is that the TextView you declared is never used since you set the layout to the one explicitly declared in the resources. To change the text on THIS textbox, you need something like

    TextEdit te = (TextEdit) findViewById(R.id.myTextEdit);
    te.setText("Yay!");

  4. #4
    Join Date
    Dec 2007
    Posts
    4

    Default

    Quote Originally Posted by Hua Yanghao View Post
    looks like the content of the window is always
    the class name following "Hello World," but where the hell does the
    "Hello World" string comes from? There's only a "Hello Android" in the
    java code.
    There are 2 ways to set your layout, you can do this by programming it all, like in your code, or you can create an .xml file wich specifies your layout. Check res/layout for that. To be able to use this xml layout, there's R.java wich provides a "link" to your layout. This is what you did with
    Code:
    setContentView(R.layout.main);
    And so, your java-layout gets replaced. It is recommend that you use, the xml layout, it allows for easy editing. You can then change the text in your code if you really need to.

    Ishtar

  5. #5
    Join Date
    Jul 2009
    Posts
    2

    Default Re: Beginner's Hello World, need help ...

    My problem is when i run the application, the emulator starts, but nothing is displayed.. who can help?
    I see a pink phone with "ANDROID" displayed on the phone and a qwerty keyboard displayed to the right of the phone...

    any suggestions....?


    package com.example.helloandroid;

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

    public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    tv.setText("Hello, Android");
    setContentView(tv);

    }
    }

  6. #6
    Join Date
    Jul 2009
    Posts
    2

    Default Re: Beginner's Hello World, need help ...

    I went back to the code and tried to run it again and it worked.... I have no idea what I did to make it work but thanks anyway....

  7. #7
    Join Date
    Dec 2008
    Location
    Texas
    Posts
    77

    Default Re: Beginner's Hello World, need help ...

    Quote Originally Posted by chozman View Post
    I see a pink phone with "ANDROID" displayed on the phone and a qwerty keyboard displayed to the right of the phone...

    any suggestions....?

    That would be the android os on the emulator booting...
    To make it work all you had to do was wait
    Hi

  8. #8
    Join Date
    Aug 2010
    Posts
    3

    Default Re: Beginner's Hello World, need help ...


    I made the same mistake - I failed to change
    <code>
    setContentView(R.layout.main);
    </code>
    to
    <code>
    setContentView(tv);
    </code>
    Which is what the starting guide tells you to do. Now all I need is a guide for writting "text" applications se I can learn about data and general java language before getting all stuck in GUI land. Thanks

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts