【问题标题】:I'm trying to make mono android simple "hello world" but I don't see "hello world" in the emulator why?我正在尝试使单声道 android 简单的“hello world”,但我在模拟器中看不到“hello world”,为什么?
【发布时间】:2011-10-17 22:31:04
【问题描述】:

我卸载了 android ask 并重新安装到 c:\androidSdktools 没有空格。 所以现在模拟器工作了,我可以看到模拟器了。

但是尝试了“hello world”文本的一些代码,当我运行应用程序并运行模拟器时,我看到了 android 模拟器,但我看不到 wnyhere“hello world”。 我不确定我是否没有做任何好事,或者可能是因为退出模拟器并停止调试时我仍然收到错误消息说:部署错误。如果我说“是”继续,那么他要求我在运行/调试它之前重建/构建我的解决方案,但它没有解决这个错误。

我不知道这个错误是否与我在 android 模拟器中没有看到任何“hello world”文本这一事实有关。

我现在尝试编写此代码:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MonoAndroidApplication1
{
    [Activity(Label = "MonoAndroidApplication1", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }
}

我有visual studio c# 2010 pro。

我试过了,这是我选择制作新的 android mono 应用程序时创建的自动代码。

但我在模拟器中没有看到任何文字。我尝试将此代码添加为:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MonoAndroidApplication1
{
    [Activity(Label = "MonoAndroidApplication1", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity
    {
        int count = 1;
        TextView tv;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            tv = new TextView(this);
            tv.Text = "hello world";
            SetContentView(tv);
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }
}

在运行模拟器时,我在模拟器中没有看到任何文本“hello world” 退出模拟器并停止调试/运行应用程序时仍然会出现此部署错误。模拟器现在运行良好,但退出时仍然出现此错误。

为什么我在模拟器上看不到文字“hello world”?

谢谢。

【问题讨论】:

  • “Cuz”不是一个词,请花时间写出完整的“因为”这个词。几乎没有足够非正式的上下文来证明使用“cuz”是合理的。

标签: c# android mono xamarin.android


【解决方案1】:

通过第二次调用 SetContentView 更改布局后,布局中不再有 Button,因此您的 FindViewById 返回 null。然后您尝试在空引用上设置事件。

看看如何阅读错误日志以便发现错误:

http://android.xamarin.com/Documentation/Guides/Android_Debug_Log

【讨论】:

    【解决方案2】:

    也可能是您没有像我解释的here 那样选择正在运行的模拟器实例。与 Monodroid 的 installation instructionsHello World tutorial 一起这样做对我来说效果很好。

    【讨论】:

    • 这让我大吃一惊。您点击运行以启动模拟器对话框,选择您正在运行的模拟器并等待。将出现一个新对话框,向您显示正在运行的模拟器,您需要在此处单击确定以开始部署应用程序。 (来自文档 - 这可能需要一段时间,但您可以部署而无需重新加载)
    【解决方案3】:

    可能你没有以正确的方式连接模拟器

    而不是按 F5 让 Visual Studio 自动附加模拟器

    尝试:

    单击按钮 Star Android Emulator Manager(它位于显示设备提示的组合框的右侧)

    在模拟器之后,它会出现在组合框中,如果没有出现,你必须退出VS然后再次打开它(我会出现,只要你打开你的模拟器)

    从组合框中选择它,然后按 F5

    完成

    【讨论】:

      【解决方案4】:

      您安装了哪个版本的 Java?我在我的第二台计算机上安装了 Java 7,发现 Monodroid 不支持 Java 7,这就是为什么我只看到模拟器而没有看到“hello world”应用程序的原因。

      我猜上周我在另一台计算机上执行此操作时,他们还没有发布 Java 7。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-12
        • 2016-04-05
        • 1970-01-01
        • 1970-01-01
        • 2016-11-25
        • 2019-01-14
        • 1970-01-01
        相关资源
        最近更新 更多