【问题标题】:Xamarin with vs : resource.Id does not contain a definition for ...Xamarin with vs : resource.Id 不包含...的定义
【发布时间】:2018-02-04 08:33:40
【问题描述】:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Media;

namespace Moosic
{
    [Activity(Label = "Moosic", MainLauncher = true, Icon = "@drawable/icon1.png")]

    public class MainActivity : Activity

    {
        MediaPlayer player;


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

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

            player = MediaPlayer.Create(this, Resource.Raw.again);

            Button button1 = FindViewById<Button>(Resource.Id.playButton);
            button1.Click += (sender, e) =>
            {
                player.Start();
            };
        }
    }
}

错误 CS0117“Resource.Id”不包含“playButton”Moosic c:\users\Farorex\source\repos\Moosic\Moosic\MainActivity.cs 25 Active 的定义

创建一个简单的媒体播放器,尝试重建解决方案并清理解决方案,但似乎不起作用

【问题讨论】:

  • 请出示您的主布局文件,并参考this

标签: android xamarin media


【解决方案1】:

您如何设置该按钮的 ID? 我见过的一个常见错误是使用 @id 而不是 @+id

在您的活动布局中,您应该有:

<Button
android:id="@+id/playButton"
...
/>

否则不会在Resource.designer.cs中创建

【讨论】:

  • 如果@id,则错误为Error: No resource found that matches the given name (at 'id' with value '@id/playButton').
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 2018-03-07
相关资源
最近更新 更多