【问题标题】:Layout does not appear in android emulatorandroid模拟器中不出现布局
【发布时间】:2012-01-08 00:14:52
【问题描述】:

我是 Android 编程新手,我正在学习来自 http://developer.android.com/resources/tutorials/views/index.html 的布局教程。完全是相对布局教程。我做了他们所说的一切,但是当我尝试在 android 模拟器中启动应用程序时,没有按钮、文本字段等。只有应用程序的名称显示在顶部。怎么了?这是模拟器的问题吗?我正在使用 Eclipse 版本:3.7.1。

编辑:

package pchot.tutorial;

import android.app.Activity;
import android.os.Bundle;

public class Tutorial1Activity extends Activity {
/** Called when the activity is first created. */
@Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    }

}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="pchot.tutorial"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Tutorial1Activity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

布局是从http://developer.android.com/resources/tutorials/views/hello-relativelayout.html复制/粘贴

编辑:

好的,问题解决了。我需要删除“Hello World,Tutorial1Activity!”来自在 Eclipse 中创建项目时自动创建的 string.xml 文件。

【问题讨论】:

  • 您知道 Logcat lampcms.blogspot.com/2010/07/… 或 DDMS developer.android.com/guide/developing/debugging/index.html 吗?我们很可能需要来自那里的信息。
  • 也许您可以向我们展示您的代码,以便我们让您知道您错在哪里?
  • 你打电话给setContentView(...)我猜?
  • 如果您发布它会帮助我们回答。
  • @TryTryAgain:我的 LogCat 日志显示了一些奇怪的东西。首先有错误:“E/AndroidRuntime(197): ERROR: thread attach failed”但在此之前,VM 似乎是如何杀死我的活动的过程:D/ActivityManager(60): Uninstalling process pchot.tutorial。可悲的是,现在我对 Android 中的任何调试都不熟悉,我才刚刚开始。

标签: android android-layout android-emulator


【解决方案1】:

您是否修改了 manifest.xml 文件?也许你没有修改它,让它知道启动的主要活动是你刚刚创建的活动。

【讨论】:

  • Activity 是我在 Eclipse 中创建项目时自动创建的,据我所知是正确的
【解决方案2】:

您没有在 onCreate() 方法中声明任何内容。

对于Button,声明Button btn = (Button)findViewById(R.id.btnSubmit)

如果您希望按钮监听点击,请实现 onClickListener。

对于TextView,声明TextView tv = (TextView)findViewById(R.id.textview)

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 2011-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    相关资源
    最近更新 更多