开发者

Cannot get a program to execute on Android

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 is generating the correct strings.xml file also. But on execution of the code I am not getting anything on the emulator screen.

Are ther开发者_如何学Goe 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, so how is that we we use it? Is there any initialization for R? If so, what it is?


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.


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!


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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜