AXML & C# - Resources does not contains a definition for ''

Emixam23Emixam23 USMember ✭✭✭

I'm coming, one more time, after deep search on google and as usual, I can't find the answer which can solves my problem...

I have these 3 errors:

Error   CS0117  'Resource.Layout' does not contain a definition for 'NativeAndroidCell'
Error   CS0117  'Resource.Id' does not contain a definition for 'Ride'  Project.Droid
Error   CS0117  'Resource.Id' does not contain a definition for 'Since' Project.Droid

from this c# code

public class NativeAndroidCellRenderer : ViewCellRenderer
{
    protected override Android.Views.View GetCellCore(Xamarin.Forms.Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
    {
        var x = (NativeCell)item;

        var view = convertView;

        if (view == null)
        {
            // no view to re-use, create new
            view = (context as Activity).LayoutInflater.Inflate(Android.Resource.Layout.NativeAndroidCell, null); //'Resource.Layout' does not contain a definition for 'NativeAndroidCell'
        }

        view.FindViewById<TextView>(Android.Resource.Id.Ride).Text = x.Ride; //'Resource.Id' does not contain a definition for 'Ride'
        view.FindViewById<TextView>(Android.Resource.Id.Since).Text = x.Since; //'Resource.Id' does not contain a definition for 'Since'    

        return view;
    }
}

So, I saw that it can comes from the build action so I set it to AndroidResource

The content is the following:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:orientation="vertical"
            android:padding="10dp"
            android:background="#FFFFFF">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FF0000"
                android:gravity="center">
                <TextView
                    android:id="@+id/Ride"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:text="Caen - Narbonne"
                    android:textColor="#FFFFFF"
                    android:textSize="30dp" />
                <TextView
                    android:id="@+id/Since"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:gravity="center_vertical"
                    android:text="6mins."
                    android:textColor="#FFFFFF" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FFFFFF">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:orientation="horizontal"
                    android:gravity="center_vertical">
                    <TextView
                        android:id="@+id/Duration"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="19mins"
                        android:textColor="#000000"
                        android:layout_weight="0"
                        android:padding="5dp" />
                    <TextView
                        android:id="@+id/Pseudo"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Emixam23"
                        android:textColor="#000000"
                        android:layout_weight="0"
                        android:padding="5dp" />
                    <TextView
                        android:id="@+id/StopNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="1 arret"
                        android:textColor="#000000"
                        android:layout_weight="0"
                        android:padding="5dp" />
                </LinearLayout>
                <Button
                    android:id="@+id/More"
                    android:layout_width="45dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:text="+" />
                <Button
                    android:id="@+id/Agree"
                    android:layout_width="45dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:text="V" />
            </RelativeLayout>
        </LinearLayout>
    </RelativeLayout>

As you can see, this NativeAndroidCell.axml seems all right, so what is happening? my Resource.Designer.cs has a build action of Compile

I'm juste trying to follow the tutorial of Customizing a ViewCell

If anyone can help, thank !

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Emixam23 - Just as a first port of call, try deleting everything inside the Resource.Designer.cs file. Then rebuild your application. I find the Resource.Designer.cs doesn't rebuild nearly as often as it should and you need to wipe it out before it rebuilds again.

  • Emixam23Emixam23 USMember ✭✭✭

    I'm again on that problem today haha, so weird because I deleted it and nothing changed, it doesn't recreate it anyway

  • BijayBudhathokiBijayBudhathoki USMember

    I am also in same problem there is no ID property in Resource class ex ...FindViewById(findViewById.Resource.Id); there is no Id Property

  • Emixam23Emixam23 USMember ✭✭✭
    @BijayBudhathoki hey !

    I found a solution, maybe it's not the thing that solves it, maybe yes, but if (from the Android SDK manager sandlone) you have the last version etc of the packages Android, then update the Android nugget that you have (they should be 23.3.0 something like that, update them to the last version so everything will match and then, it'll work. Before try that on your project, test from another solution :)

    Best,

    Max
  • FlavioARFlavioAR BRMember

    Great tip. I've been trying to solve this problem for a long time. Thank you!

  • iamaurousiamaurous PHMember ✭✭

    Did anyone get any solution for this? Also having the same problem and I didn't have any luck from updating the android nugget. Thanks guys

  • Emixam23Emixam23 USMember ✭✭✭

    Yep, I mean, I think so..

    You want the last update of the nuget package for android? Then update your android lib from the Android SDK Manager.

    I think if you want the last update, you need Android 8, but you have to try and confirm ;)

    Best,

    Max

  • Wonde_ManWonde_Man ETMember ✭✭

    The best and easy solution is clear the Main.axml page and Reset and it is working.
    B) B) B) B)

  • DakkonDakkon Member

    In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

  • MatExMatEx NLMember ✭✭

    I also copy-pasted code from another project into an *.axml layout file, and got this error. Here's what solved it for me: I simply added a new Button in the *.axml file, saved it, built it, and it worked. Afterwards I removed the Button, and it still worked. Not sure what causes this, but my guess is that inside the Resource.Designer.cs file you see this Attribute on the class: [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
    And it seems that the way the compiler interprets this is that a copy-paste doesn't qualify as file modification, but if you actually edit it with the cursor and type, then that does. ¯\_(ツ)_/¯

  • NicolaePopovNicolaePopov USMember ✭✭

    @AdamP said:
    @Emixam23 - Just as a first port of call, try deleting everything inside the Resource.Designer.cs file. Then rebuild your application. I find the Resource.Designer.cs doesn't rebuild nearly as often as it should and you need to wipe it out before it rebuilds again.

    this helped me, thanks

  • GlennErlerGlennErler USMember ✭✭

    This has plagued me off and on. Project would build but would not deploy. I would the "resouce. does not contain.....etc". What was the culprit for me was excess white space in the axml file. I would have elements where I put the "/>" on another line for ease. Well... it don like that. No white space in the after the last attribute and all of my problems went away. Another Xamarin ooops!1

  • KiraguGathuaKiraguGathua Member

    Solved this error by saving .axml, cleaning project and finally building project

  • RobertMolloyRobertMolloy USMember

    @Dakkon said:
    In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

    This did it for me. Thanks!

  • DakkonDakkon Member

    I'm glad I was able to help.

    @RobertMolloy said:

    @Dakkon said:
    In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

    This did it for me. Thanks!

Sign In or Register to comment.