【问题标题】:Android app does not run on emulatorAndroid 应用无法在模拟器上运行
【发布时间】:2011-09-28 17:49:53
【问题描述】:

我正在尝试使用 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 上运行。

谢谢。

【问题讨论】:

  • 你有完整的清单文件吗?
  • 在主屏幕可见后尝试重新运行应用程序(并且您解锁了键锁)。如果模拟器正在运行,您的应用将被部署到该模拟器上,而不是启动一个新的。

标签: android eclipse android-emulator


【解决方案1】:

我认为您需要创建一个快速布局,并将内容设置为布局。 在 /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 并更改其文本...

告诉我们进展如何。

-serkan

【讨论】:

    【解决方案2】:

    解锁模拟器并将您的应用重新部署到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      相关资源
      最近更新 更多