We help IT Professionals succeed at work.

unable to execute hello world

KaranGupta
KaranGupta asked
on
Hi

I have just started andriod for that I have created the hello world sample.

But when I run the project I see only blank screen. Am I missing something

I am attaching the project. Please help me out.

P.S - Please rename the file to .rar

Regards
Karan   workspace.txt
Comment
Watch Question

It seems you'd better write :
tv.setText("Hello, Android");
AFTER the line containing :
setContentView(tv);

Author

Commented:
HI

Still I am not getting hello world

package Hello.World.Package;

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


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

Open in new window



Actually, you must tell android where to draw your widgets like a txtview one.
This should work, assuming you have a main.xml file in your (hello_world project root)/res/layout directory.

If you are using Eclipse, double-clicking on that file will allow you to place different widgets on your layout.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this);        
        setContentView(tv);
        tv.setText("Hello, Android");

Open in new window

Author

Commented:
HI OHUPE

Still the result is same. I am attaching the screen shot. Have you tried this code on your system. If it works well then probably there might be some issue in the installation of the sdk or may be some issue in settings.

Kindly advice

Regards
Karan Gupta
andriod-Hello-World.jpg
I think it might be a configuration issue. Did you read the console content while lauching the helloworld app ?
Remember that the target you choosed is level 14, that means Android 4.0 OS. Did you update your SDKs using the "Window"->"Android SDK Manager" menu item ?
s-shot.jpg

Author

Commented:
Hi OHUPE

Thanks for the reply

"Did you read the console content while lauching the helloworld app ?"

[Comments]: I am not getting it. Could you please elaborate this?


"Did you update your SDKs using the "Window"->"Android SDK Manager" menu item ?"

[Comments]: I am attaching the screenshot for "Window"->"Android SDK Manager". Please check if everything is properly installed.

Regards
Karan Gupta
andriod-Hello-World.jpg
Hi KaranGupta,
Your sdk install seems to be fine.
Your emulator screenshot looks like an emulator that didn't really start up or which is stucked launching the app. That's why I attached this screenshot with the avd's settings I'm using. By the way, you can read console messages on the lower part of the pic.

I hope it  helps.
capture.jpg

Explore More ContentExplore courses, solutions, and other research materials related to this topic.