c# - Xamarin - Resource.X 不包含 Y 的定义

标签 c# android xamarin android-resources

我使用以下教程创建了一个基本的 SQLite Xamarin Android 应用程序: https://www.c-sharpcorner.com/article/xamarin-android-sqlite-database/ .

我使用了与该网站几乎相同的代码,但我对其进行了修改以满足我的需要。

但是,应用程序没有构建,我得到的错误是:

  • 错误 CS0117“Resource.Id”不包含“add_date_input”的定义
  • 错误 CS0117“Resource.Id”不包含“add_save”的定义
  • 错误 CS0117“Resource.Layout”不包含“Main”的定义
  • 错误 CS0117“Resource.Layout”不包含“AddReminder”的定义

等等(所有相同类型的错误)...

我的 main.axml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/addReminder" />
<ListView
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/reminder_listview" />
</LinearLayout>

我的 MainActivity.cs:

using Android.App;
using Android.Widget;
using Android.OS;
using RemindersDBModel;
using RemindersDBHelper;
using System.Collections.Generic;
using RemindifyListViewAdapter;
using System;
using Android;

namespace ReminderMain
{
    [Activity(Label = "Reminder", MainLauncher = true)]
    public class MainActivity : Activity
    {
        Button addReminderBtn;
        ListView listView;
        List<DBModel> listSource = new List<DBModel>();
        DBHelper db;

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

            SetContentView(Resource.Layout.Main);

            db = new DBHelper();
            db.createDatabase();

            addReminderBtn = FindViewById<Button>(Resource.Id.addReminder);
            addReminderBtn.Click += (sender, e) =>
            {
                StartActivity(typeof(AddReminderActivity));
            };

            listView.ItemClick += ListView_ItemClick;

            loadReminders();
        }

        private void loadReminders()
        {
            listSource = db.selectTable();
            var adapter = new ListViewAdapter(this, listSource);
            listView.Adapter = adapter;
        }
    }
}

到目前为止我尝试了什么:

  • 清理和重建解决方案
  • 删除“Resource.Designer.cs”的内容
  • 重新安装 Android SDK
  • 正在添加 <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile> <AndroidResgenClass>Resource</AndroidResgenClass>到 Reminder.csproj

有解决这个问题的想法吗?

提前致谢。问候

最佳答案

Visual Studio 的编译器有时会出错。

尝试删除bin和obj文件夹,然后重启你的VS。

关于c# - Xamarin - Resource.X 不包含 Y 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49631222/

相关文章:

c# - 控制台应用程序 : Closing Window vs End of Program

c# - 尝试访问 asp.net 中继器内的按钮

android - 使用 glide 在 ActionBar 上设置图标

c# - 在 Xamarin Forms Shell 中隐藏 TabBar

c# - Monotouch/Xamarin 绑定(bind)继承

c# - 从字典中获取值的计数 C#

android - 如何通过 Intent 添加名字和姓氏的联系人

android - 使用 GPUImage Android 进行视频处理

visual-studio - 如何将 OSX Xamarin 项目迁移到 Windows 10 上的 Visual Studio?

c# - 使用 MVC、WCF、EF 的应用程序架构