views:

188

answers:

5

I am new to android programming. I have installed the eclipse and android SDK. After doing all the settings. I have executed the HelloWorld program. The program, after execution is generating the correct strings.xml file also. But on execution of the code i am not getting anything on the emulator screen.

Is there any additional settings required for the code to execute..

Also in the line: setContentView(R.layout.main); that we use in most of our code what is R? We don't initialize it. then how do we use it?? is there any initialization for R? if yes then can any one tell me what it is??

Thanks in advance..

A: 

In most cases I do not get the app on the emulator screen. I press the menu button which than starts the app. Or sometimes I have to open the applications window on the phone to find the application icon to start it.

jdekeij
+2  A: 

Hi!
If you use eclipse with ADT plugin you can start a simple project almost immediately. When you create a project with initial Activity class you should be able to run it on emulator and it should display hello string.
Generally, good way to start with android is the tutorial provided by google: http://developer.android.com/guide/tutorials/notepad/index.html

Regarding this R file - it is autogenerated file containing identifiers for all resources from your project "res" folder (layouts, strings, drawables, etc.). Thanks to this file you can refer to your resources. Many method from Android API take as a parameter the ID from R file, like for example setContentView().
Regards and good luck with Android!

Ramps
thanx dude. for ur answer to second question.about 1st question: as I've mentioned:- I have done all the settings as mentioned on the developers blog.The program on execution has generated the xml file also. But on the simulator screen i am getting nothing but android written which after some times turn to a mobile screen. [Thats what simulators feature is].Do i have to do anything else to see the simple text output. Like seting the layout..My code is:--
Mew 3.2
My code is:--import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class Hello 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("I am Mew"); setContentView(tv); }}is there anything else to be written here???
Mew 3.2
Your code is perfectly OK, emulator should display the content of your TextView. But you can check two things:1. Check your AndroidManifest.xml - it should contain your activity (sth like: <activity android:name=".Hello" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>)2. In eclipse, check your "Console" for error messages while installing your application on emulator.
Ramps
+3  A: 

R is referencing your layout xml located at /res/layout/main.xml. The class your extending (Activity) takes care of the instantiating if i'm not mistaken.

Also the emulator is known to take a really really long time to start up and run. What I do is start an emulator instance. When you run the ant install script, it will re-install your program on the emulator. That's better than continuously restarting.

bigjust
A: 

Have you created an AVD (Android Virtual Device) matching your project setup ? Eclipse -> Window -> Android SDK and AVD Manager

R is a class generated by aapt tool from resources containing static members, you don't have to initialize it.

dtmilano
A: 

R is generated at compile time. It has handles for all of the resources in Android that you provided files for.

Ichorus