我使用以下教程创建了一个基本的 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/