繁体   English   中英

“Resource.Layout”不包含 xamarin 中“activity_main”的定义

[英]'Resource.Layout' does not contain a definition for 'activity_main' in xamarin

我收到'Resource.Layout'的错误,不包含 'activity_main' 的定义 但我很困惑,为什么它会显示这种类型的错误。 因为activity_mainResource.Layout 中可用,但仍然显示相同的错误。

这是代码,

资源 => 布局 => activity_main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:minWidth="25px"
    android:minHeight="25px">
    <android.webkit.WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/webView" />
</LinearLayout>

资源 => MainActivity.cs

[Activity(Label = "BSSTMatrimonial", MainLauncher = true)]
    public class MainActivity : Activity
    {
        WebView webView = null;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

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

           // webView = FindViewById<WebView>(Resource.Id.webView);
           //webView.SetWebViewClient(new ExtendWebViewClient());

            webView.LoadUrl("www.bsstmatrimony.com");
            WebSettings webSettings = webView.Settings;
            webSettings.JavaScriptEnabled = true;
        }
    }

尝试清理并重建您的解决方案。 甚至您可以删除并重新添加.axml文件。 如果仍然不起作用,请点击 .axml 文件

  • 转到 properties -->Build action 确保 Build action 设置为AndroidResource

这是一个可以忽略的无害错误,但您可以在文件中搜索 Resource.Designer.cs。 您可能有两个,一个在项目的 obj/debug 文件夹中,另一个在项目的 Resources 文件夹中。 检查两者中的activity_main,您的Resources文件夹中的文件可能没有它。

我经常遇到这个问题。 我认为问题在于随着 xamarin 的更新,它会更改模板中的变量名和文件名。 因此,如果您正在使用教程中的代码,如果您看到此问题,则它可能已过时。 这意味着您必须重命名某些内容以适合当前模板。

在这种情况下,我不得不改变

SetContentView(Resource.Layout.Main);

SetContentView(Resource.Layout.activity_main);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM