C# I';“我试图让单安卓变得简单”;“你好,世界”;但我不知道';“我看不见”;“你好,世界”;在模拟器中为什么?

C# I';“我试图让单安卓变得简单”;“你好,世界”;但我不知道';“我看不见”;“你好,世界”;在模拟器中为什么?,c#,android,mono,xamarin.android,C#,Android,Mono,Xamarin.android,我卸载了android ask,并将其重新安装到c:\androidSdktools(无空格)。 现在模拟器工作了,我可以看到模拟器了 但是尝试了一些“hello world”文本的代码,当我运行应用程序和模拟器时,我看到了android模拟器,但我看不到wnyhere“hello world”。 我不确定我是否做得不好,或者可能是因为我在退出仿真器并停止调试时仍然出错,我收到了错误消息,比如:部署错误。如果我说“是”继续,那么他会在我运行/调试解决方案之前要求我重新构建/构建解决方案。我这样做

我卸载了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++); };
        }
    }
}
使用系统;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
命名空间monoandroid应用程序1
{
[活动(Label=“MonoAndroidApplication1”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课堂活动1:活动
{
整数计数=1;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
Button Button=FindViewById(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++); };
        }
    }
}
使用系统;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
命名空间monoandroid应用程序1
{
[活动(Label=“MonoAndroidApplication1”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课堂活动1:活动
{
整数计数=1;
文本视图电视;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
tv=新文本视图(此);
tv.Text=“你好,世界”;
设置内容视图(电视);
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
Button Button=FindViewById(Resource.Id.MyButton);
button.Click+=delegate{button.Text=string.Format(“{0}clicks!”,count++);};
}
}
}
同样,在运行模拟器时,我没有在模拟器中看到任何文本“hello world” 并且在退出emulator并停止调试/运行应用程序时仍会出现此部署错误。模拟器现在运行正常,但退出时仍会出现此错误

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


谢谢。

第二次调用SetContentView更改布局后,布局中不再有按钮,因此FindViewById将返回null。然后,您尝试将事件设置为空引用

查看如何读取错误日志,以便查找错误:


也可能是您没有像我解释的那样选择正在运行的emulator实例。与和for Monodroid一起使用对我来说效果很好。

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


我猜上个星期左右,当我在我的另一台计算机上进行此操作时,他们没有发布Java 7。

可能您没有以正确的方式连接仿真器

而不是按F5让visual studio自动附加模拟器

尝试:

单击Star Android Emulator Manager按钮(位于组合框右侧,提示输入设备)

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

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


完成

“Cuz”不是一个单词,请花时间写出完整的单词“因为”。事实上,没有任何非正式的上下文足以证明“cuz”的使用是正当的。这正是我被绊倒的原因。点击run以启动emulator对话框,选择正在运行的emulator并等待。将出现一个新对话框,向您显示正在运行的模拟器,您需要单击此处的“确定”开始部署应用程序。(来自文档-可能需要一段时间,但您可以在不重新加载的情况下进行部署)