Forum Xamarin.Android

Why do I get this error about string types?

AbhishekJoshi.5930AbhishekJoshi.5930 USMember, University

I was trying out the Xamarin Hello, Android Phoneword tutorial, and when I try to build the project, I get this error:

Error: String types not allowed (at 'id' with value ' @+id/CallButton'). (Phoneword)

What can I do to fix the error?

Tagged:

Best Answer

Answers

  • CheesebaronCheesebaron DKInsider, University mod

    Post the AXML content here (remember to mark it and press the C button in the toolbar) easier to see what is going on.

  • AbhishekJoshi.5930AbhishekJoshi.5930 USMember, University
    edited April 2015

    From the main.axml page :

    <?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="Call" android:layout_width="match_parent" android:layout_height="wrap_content" android:id=" @+id/CallButton" /> </LinearLayout>

  • AbhishekJoshi.5930AbhishekJoshi.5930 USMember, University
    edited April 2015

    The mainactivity.cs file :

    `
    using System;
    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, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
    int count = 1;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
    
            // Set our view from the "main" layout resource
            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);
    
            // Disable the "Call" button
            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();
            };
        }
    }
    

    }

    `

  • AbhishekJoshi.5930AbhishekJoshi.5930 USMember, University

    My other class, phonetranslator.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;
        }
    }
    

    }`

  • Zed.9306Zed.9306 USMember

    Same question here. Just beginner : (

  • FndFnd TWMember
    edited May 2015

    Try to Clear and Build it again?
    I guess it's resource problem

  • ChrisFletcherChrisFletcher USMember

    I'm having the exact same problem. This is freaking ridiculous, how am I suppose to learn how to use xamarin if the first tutorial exercise doesn't work!!!!

    I get the following error messages:

    E:\My Documents\My Documents\Xamarin\Projects\Phoneword\Phoneword\Resources\layout\Main.axml(0,0): Error APT0000: String types not allowed (at 'id' with value ' @+id/TranslateButton'). (APT0000) (Phoneword)

    AND:

    E:\My Documents\My Documents\Xamarin\Projects\Phoneword\Phoneword\Resources\layout\Main.axml(0,0): Error APT0000: String types not allowed (at 'id' with value ' @+id/CallButton'). (APT0000) (Phoneword)

  • CheesebaronCheesebaron DKInsider, University mod

    Builds fine here. What version of Xamarin.Android are you using?

  • ChrisFletcherChrisFletcher USMember

    The details are:

    Xamarin.Android
    Version: 5.1.4 (Trial Edition)
    Android SDK: C:\Users\Chris\AppData\Local\Android\android-sdk
    Supported Android versions:
    4.0.3 (API level 15)
    4.4 (API level 19)
    5.0 (API level 21)
    Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
    java version "1.7.0_71"
    Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
    Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

  • ChrisFletcherChrisFletcher USMember

    I just updated to a newer version of Xamarin.Andoid (Version: 5.1.5 (Trial Edition)) but the problem persists.

    How can such a simple button naming issue cause so much hassle?!

  • To run Successfully the Demo App, you can just let the default @+Id name !

  • Same error ...I also beginner....if start having such a hell error...how to learn..

  • FinnyFinny GBMember

    Yeah, it has some problem. When solve it ?

  • FinnyFinny GBMember

    Yeah, it has casesam.co.uk some problem. When solve it ?

  • FazaHarbiFazaHarbi USMember

    As @CodeRinse said, for some reasons an extra space is added in the Main.xaml file, make sure that to correct as he points out.
    Second issue:
    You build your solution and bam: Resource doesn't exist in this context.
    Ok, so don't try to go higher and add Android.Resource "in case"...it'd work. It doesn't.
    Don't touch this code except for where we are asked to change the Activity Label :
    [Activity (Label = "Phone Word", MainLauncher = true, Icon = "@drawable/icon")]

    Then scroll down the files in phoneword , you'll find the directory Resources, get inside and compile the file Resource.designer.cs .
    Now, if you did like me aka: go all free versions, you'll have a message telliing you that you're missing ..I don't remember the name. You have 3 choices proposed: Purchase the Indie version, Get the not free version of Xamarin Studio, or use the Trial.

    I went for the Trial.
    Now go back to your namespace phoneword(second "item" from the top in the Solution display window) click on the gear, click on build phoneword and tht's it.

    Hope it helped!

Sign In or Register to comment.