2

I created a Cross-Plattform-Application-Project (Native Shared) with Xamarin (up to date) and Visual Studio 2015.

I followed the tutorial "Hello Android" and finished it, but when building the project I´ll get this error message:

Severity Code Description Project File Line Suppression State Error CS0117 'Resource.Id' does not contain a definition for 'CallButton' HelloApp.Droid C:\Users\username\documents\visual studio 2015\Projects\HelloApp\HelloApp\HelloApp\HelloApp.Droid\MainActivity.cs 26 Active

(Same for the other Widgets)

I tried different API-Levels/Reinstalled sdks and packages, as stated in this Question,but it wont work for me. I installed Android Build Tools for different API-Levels and deinstalled others, but this wont change a thing.

I also tried the solution stated in this question and tried to clean and rebuild the solution several times, i also deleted the zips in the xamarin-zips folder. The Resource.designer.cs gets compiled every time and seems fine... Also the Build Action is correct for all files.

Can someone please help?

PS: On Mac it works perfectly fine, but i want to develop on Windows with Visual Studio...

Link to the tutorial: https://developer.xamarin.com/guides/android/getting_started/hello,android/hello,android_quickstart/

For detailed information, here my source code:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <application android:label="HelloApp.Droid"></application>
</manifest>

PhonewordTranslator.cs

using System.Text;
using System;

namespace Core
{
    public static class PhonewordTranslator
    {
        public static string ToNumber(string raw)
        {
            if (string.IsNullOrWhiteSpace(raw))
                return "";
            else
                raw = raw.ToUpperInvariant();

            var newNumber = new StringBuilder();
            foreach (var c in raw)
            {
                if (" -0123456789".Contains(c))
                    newNumber.Append(c);
                else
                {
                    var result = TranslateToNumber(c);
                    if (result != null)
                        newNumber.Append(result);
                }
                // otherwise we've skipped a non-numeric char
            }
            return newNumber.ToString();
        }
        static bool Contains(this string keyString, char c)
        {
            return keyString.IndexOf(c) >= 0;
        }
        static int? TranslateToNumber(char c)
        {
            if ("ABC".Contains(c))
                return 2;
            else if ("DEF".Contains(c))
                return 3;
            else if ("GHI".Contains(c))
                return 4;
            else if ("JKL".Contains(c))
                return 5;
            else if ("MNO".Contains(c))
                return 6;
            else if ("PQRS".Contains(c))
                return 7;
            else if ("TUV".Contains(c))
                return 8;
            else if ("WXYZ".Contains(c))
                return 9;
            return null;
        }
    }
}

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:text="Enter a Phoneword"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/PhoneNumberText"
        android:text="1-855-XAMARIN" />
    <Button
        android:text="Translate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/TranslateButton" />
    <Button
        android:text="CallButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CallButton" />
</LinearLayout>

MainActivity.cs

using System;
using Android;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Phoneword
{
    [Activity(Label = "Phoneword", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource

           //** ERROR IN THE NEXT 4 LINES!!! **
            SetContentView(Resource.Layout.Main);

            EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
            Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
            Button callButton = FindViewById<Button>(Resource.Id.CallButton);

            callButton.Enabled = false;

            // Add code to translate number
            string translatedNumber = string.Empty;

            translateButton.Click += (object sender, EventArgs e) =>
            {
                // Translate user's alphanumeric phone number to numeric
                translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
                if (String.IsNullOrWhiteSpace(translatedNumber))
                {
                    callButton.Text = "Call";
                    callButton.Enabled = false;
                }
                else
                {
                    callButton.Text = "Call " + translatedNumber;
                    callButton.Enabled = true;
                }
            };

            callButton.Click += (object sender, EventArgs e) =>
            {
                // On "Call" button click, try to dial phone number.
                var callDialog = new AlertDialog.Builder(this);
                callDialog.SetMessage("Call " + translatedNumber + "?");
                callDialog.SetNeutralButton("Call", delegate {
                    // Create intent to dial phone
                    var callIntent = new Intent(Intent.ActionCall);
                    callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
                    StartActivity(callIntent);
                });
                callDialog.SetNegativeButton("Cancel", delegate { });

                // Show the alert dialog to the user and wait for response.
                callDialog.Show();
            };

            // Our code will go here
        }
    }
}

Resource.designer.cs

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[assembly: global::Android.Runtime.ResourceDesignerAttribute("HelloApp.Droid.Resource", IsApplication=true)]

namespace HelloApp.Droid
{


    [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]
    public partial class Resource
    {

        static Resource()
        {
            global::Android.Runtime.ResourceIdManager.UpdateIdValues();
        }

        public static void UpdateIdValues()
        {
        }

        public partial class Attribute
        {

            static Attribute()
            {
                global::Android.Runtime.ResourceIdManager.UpdateIdValues();
            }

            private Attribute()
            {
            }
        }

        public partial class Drawable
        {

            // aapt resource value: 0x7f020000
            public const int Icon = 2130837504;

            static Drawable()
            {
                global::Android.Runtime.ResourceIdManager.UpdateIdValues();
            }

            private Drawable()
            {
            }
        }

        public partial class Id
        {

            // aapt resource value: 0x7f050003
            public const int CallButton = 2131034115;

            // aapt resource value: 0x7f050001
            public const int PhoneNumberText = 2131034113;

            // aapt resource value: 0x7f050002
            public const int TranslateButton = 2131034114;

            // aapt resource value: 0x7f050000
            public const int textView1 = 2131034112;

            static Id()
            {
                global::Android.Runtime.ResourceIdManager.UpdateIdValues();
            }

            private Id()
            {
            }
        }

        public partial class Layout
        {

            // aapt resource value: 0x7f030000
            public const int layout1 = 2130903040;

            // aapt resource value: 0x7f030001
            public const int Main = 2130903041;

            static Layout()
            {
                global::Android.Runtime.ResourceIdManager.UpdateIdValues();
            }

            private Layout()
            {
            }
        }

        public partial class String
        {

            // aapt resource value: 0x7f040001
            public const int app_name = 2130968577;

            // aapt resource value: 0x7f040000
            public const int hello = 2130968576;

            static String()
            {
                global::Android.Runtime.ResourceIdManager.UpdateIdValues();
            }

            private String()
            {
            }
        }
    }
}
#pragma warning restore 1591
Community
  • 1
  • 1
Kevin de Goede
  • 429
  • 6
  • 12
  • It's odd that the namespace of the Resource-class "HelloApp.Droid" is not included via a using-statement in your activity. Do you have another class in the project that is named "Resource"? Can you try to clean and rebuild the project via the context menu of the solution? What happens if you select the Resource-class and you press the F12 (Go to definition) key? – Stefan Wanitzek Sep 20 '16 at 15:50

2 Answers2

5

1.Delete all the things in "{yourAPPlocation}\Resources\Resource.designer.cs".

2.Rebuild the whole project.

3.Copy whole "{yourAPPlocation}\Resources\Resource.designer.cs" newborn and paste to "{yourAPPlocation}\obj\Debug\81\designtime\Resource.designer.cs".

Then it works!

Hope that will succeed on your project too.

Jin-Hao Yang
  • 66
  • 1
  • 2
1

I had this error too What I did is just to save the file and it fixed ! Hopefully works fro you.

JPilson
  • 1,075
  • 11
  • 10