Android 应用程序无法在模拟器上运行

标签 android eclipse android-emulator

我正在尝试使用 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/

相关文章:

Eclipse Juno 最大化分屏

java - 在 MANIFEST 文件中使用外部 Bundle-Localization 路径

android - 如何模拟一个非常慢的安卓手机?

java - 我的 android xml 解析应用程序在 android 模拟器中意外停止

java - 使用日历在每个午夜重置计算的步数

Android HttpPost 通过 Yii 框架返回 500

android - AVD 在 Android 屏幕后直接崩溃

eclipse - Buildship如何在项目范围内设置环境变量

android - Android API 级别从 18 更改为 17,但 android 从来没有 "Boots Up"

android - HTML5 视频 : How to enable *non-muted* autoplay in Chrome for Android