我正在尝试使用 Eclipse 运行 Hello World 教程代码。我已经设置了一个 AVD,但是当我尝试运行代码时,模拟器加载到主屏幕并且应用程序没有出现。控制台中没有显示任何错误,并且 logcat 完全是空的(我还让它运行了 30 分钟)。
控制台输出:
[2011-09-28 18:00:31 - AndroidTest] ------------------------------
[2011-09-28 18:00:31 - AndroidTest] Android 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'
代码:
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);
}
}
我在 Windows 7 x64 上运行。
谢谢。
最佳答案
我认为您需要创建一个快速布局,并将内容设置到布局中。 在您的/layout 文件夹中创建此 home.xml
<?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>
在 onCreate 中,执行此操作
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
这应该可以,
稍后,您可以引用您的 TextView 并更改其文本...
让我们知道进展如何。
-塞尔坎
关于Android 应用程序无法在模拟器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7587376/