c# - CS0117 - Xamarin not detecting 'Resources' folders and files -
i have been developing xamarin.forms
app, on ios , android. have run problem whereby code unable see resources being referenced in mainactivity.cs
. have same error 2 different resources.
i following along udemy course , instructor emphasising manually building of xml
files, hence 2 types, axml
, xml
.
first error
/users/richardcurteis/desktop/onedrive/devshared/xamarinprojects/notetaker/droid/mainactivity.cs(35,35): error cs0117: `notetaker.droid.resource' not contain definition `menu' (cs0117) (notetaker.droid)
second error:
/users/richardcurteis/desktop/onedrive/devshared/xamarinprojects/notetaker/droid/mainactivity.cs(21,21): error cs0117: `notetaker.droid.resource.id' not contain definition `action_add' (cs0117) (notetaker.droid)
mainactivity.cs
using system; using android.app; using android.content; using android.runtime; using android.views; using android.widget; using android.os; using supporttoolbar = android.support.v7.widget.toolbar; using android.support.v7.app; using system.collections.generic; namespace notetaker.droid { [activity (label = "note taker", mainlauncher = true, icon = "@drawable/icon")] public class mainactivity : appcompatactivity { int count = 1; private supporttoolbar toolbar; protected override void oncreate (bundle savedinstancestate) { xamarin.insights.initialize (xamarininsights.apikey, this); base.oncreate (savedinstancestate); new database (); // set our view "main" layout resource setcontentview (resource.layout.main); toolbar = findviewbyid<supporttoolbar> (resource.id.toolbar); setsupportactionbar (toolbar); // our button layout resource, // , attach event button button = findviewbyid<button> (resource.id.mybutton); button.click += delegate { button.text = string.format ("{0} clicks!", count++); }; } public override bool oncreateoptionsmenu (imenu menu) { menuinflater.inflate (resource.menu.addmenu, menu); return base.oncreateoptionsmenu (menu); } public override bool onoptionsitemselected (imenuitem item) { switch (item.itemid) { case resource.id.action_add: console.writeline ("add button clicked"); return true; default: return base.onoptionsitemselected (item); } } } }
addmenu.xml
contains action_add
id.
<?xml version="1.0" encoding="utf-8" ?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/action_add" android:icon="@drawable/addicon" android:title="add" app:showasaction="always" /> </menu>
resources
tree
~/desktop/onedrive/devshared/xamarinprojects/notetaker/droid tree resources/ resources/ ├── aboutresources.txt ├── resource.designer.cs ├── drawable │ └── addicon.png ├── layout │ ├── main.axml │ └── toolbar.xml ├── menu │ └── addmenu.xml ├── mipmap-hdpi │ └── icon.png ├── mipmap-mdpi │ └── icon.png ├── mipmap-xhdpi │ └── icon.png ├── mipmap-xxhdpi │ └── icon.png ├── mipmap-xxxhdpi │ └── icon.png └── values ├── strings.xml └── styles.xml 9 directories, 13 files
ok figured out issue was. when had been coding had placed 'menu' folder in wrong directory. had done right clicking accidentally 'layout' , clicking 'add/new folder'.
the problem came when manually dragged , dropped folder correct place. but seems xamarin recognises files , folders added via right click option , compiler saw files in original, incorrect location.
however deleting files right click/'remove' does not solve issue. whilst target file removed xamarin ui, not removed project directory on disk , such new file same name cannot added. had navigate project folder , run rm -rf menu
remove it. go xamarin , right click/add/new folder , new file.
following cleaned project , rebuilt , worked charm.
this post on xamarin forums tipped me off issue was.
Comments
Post a Comment