Reputation: 482
I am getting an error of 'Resource.Layout' does not contain a definition for 'activity_main'. But I am confused, why it is showing this type of error. Because activity_main is available in Resource.Layout, but still showing the same error.
Here is the code,
Resources => 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>
Resources => 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;
}
}
Upvotes: 0
Views: 3912
Reputation: 636
I've been encountering this problem a lot. I think the problem lies in the fact that as xamarin is updated, it changes the variable names and file names in the templates. So if you are using code from a tutorial, if you are seeing this problem, its likely outdated. This means that you have to rename something to fit the current template.
In this case I had to change
SetContentView(Resource.Layout.Main);
to
SetContentView(Resource.Layout.activity_main);
Upvotes: 0
Reputation: 352
It is a harmless error that can be ignored but you can search your files for Resource.Designer.cs. It is likely that you have two, one in your project's obj/debug folder and one in your project's Resources folder. Check for activity_main in both, it is possible that the file in your Resources folder doesn't have it.
Upvotes: 0
Reputation: 17482
Try to Clean & Rebuild your solution. Even you can delete & re-add .axml
file.
If still won't work write click on .axml file
Upvotes: 1