xamarin C#:'资源'不包含'Id'的定义

时间:2017-05-06 09:16:56

标签: c# android xamarin xamarin.android

我最近开始与Xamarin合作在C#中构建Android应用程序。 特别是有一个问题让我很难取得任何进展: error CS0117

我有两个相同的项目,问题只出现在其中一个项目中。 它最初发生在两者,但重建几次固定第一个。 第二个似乎更持久。 我真的需要找到这个问题的解决方案,因为引用是非常基础和需要的。更不用说,它发生在每个新项目中。 这是我的代码: NoteMath

using System;
using Android.App;
using Android.Content;
using Android.Widget;
using Android.OS;

namespace NoteMath_v1._0._1
{
    [Activity(Label = "noteMath", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Window.RequestFeature(Android.Views.WindowFeatures.NoTitle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            EditText etInput = FindViewById<EditText>(Resource.Id.etInput);
            TextView tvConsole = FindViewById<TextView>(Resource.Id.tvConsole);
            etInput.KeyPress += (object sender, EditText.KeyEventArgs e) =>
            {
                e.Handled = false;
                if (e.Event.Action == Android.Views.KeyEventActions.Down && e.KeyCode == Android.Views.Keycode.Enter)
                {
                    tvConsole.Append("\n>" + HandleInput.TransferInput(etInput.Text));
                    etInput.Text = "";
                    e.Handled = true;
                }
            };
        }
    }
}

我提前感谢你。

4 个答案:

答案 0 :(得分:3)

您发布的代码看起来不错。这个错误显然不是来自那里。你的任何资源布局或xml文件都有问题。

问题实际上是Visual Studio不会在Errors面板中显示资源生成错误,尽管它应该是这样的(我认为这将在未来版本中修复)。目前它只是告诉你类Id不存在。

Resources.designer.cs是编辑任何资源文件时由Xamarin生成的类。它包含对xml / axml文件中的任何声明,id等的引用。如果资源有错误,Resources.designer.cs生成将失败,但您会得到一个非常模糊的错误提示。

好消息是,您可以通过将构建输出详细程度更改为“详细”来查看生成错误:

enter image description here enter image description here

现在再次编译项目并检查输出窗口。它会告诉你究竟是什么问题。

修复后,将生成Resource.Id课程。

答案 1 :(得分:0)

对我来说,这可行:

步骤1。 项目>更新NugetPackages

第2步。 生成>全部清除

第3步。 构建>全部构建

答案 2 :(得分:0)

我超级新。唯一对我有用的方法是在项目根目录中手动运行此powershell脚本:

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

我不确定为什么实时显示/构建输出没有更多帮助,或者Visual Studio无法在我的xamarin项目中正确清除这些文件。

特别感谢这个人:

https://montemagno.com/easily-clean-bin-obj-folders/

答案 3 :(得分:-1)

只需更新Nuget软件包即可为我解决该问题!

相关问题