Android app does not run on emulator
I'm trying to run the Hello World tutorial code using Eclipse. I've set up an AVD but when I try and run the code, the emulator loads to the home screen and the app does not appear. No errors are shown in the console, and the logcat is completely empty (I've also left it running for 30 minutes).
Console output:
[2011-09-28 18:00:31 - AndroidTest] ------------------------------
[2011-09-28 18:00:31 - AndroidTest] Andr开发者_如何学编程oid Launch!
[2011-09-28 18:00:31 - AndroidTest] adb is running normally.
[2011-09-28 18:00:31 - AndroidTest] Performing com.example.helloandroid.AndroidTest activity launch
[2011-09-28 18:00:31 - AndroidTest] Automatic Target Mode: launching new emulator with compatible AVD 'myAVD'
[2011-09-28 18:00:31 - AndroidTest] Launching a new emulator with Virtual Device 'myAVD'
Code:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidTest 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 World!");
setContentView(tv);
}
}
I'm running on Windows 7 x64.
Thanks.
I think you need to create a quick layout, and set the content to the layout. Create this home.xml in your /layout folder
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/my_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="24sp"
/>
</LinearLayout>
In onCreate, do this
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
This should work,
Later, you can reference to your TextView and change its text...
Let us know how it goes.
-serkan
Unlock the emulator and redeploy your app to it.
精彩评论