Question

I am starting out in Xamarin to create an Android app for the first time, so I am following the most basic Xamarin Android tutorial. I get to the point where I am editing my Strings.xml file for my UI controls. I do so, and compile, and get:

C:\...\main.xml(0,0): Error: No resource found that matches the given name (at 'text' with value '@string/hello'). (AndroidHello)

I don't have a main.xml, but I do have a Main.axml, which was apparently generated with the solution. Am I expected to edit this file to match my .cs files? That doesn't seem right at all. Or should it be re-generated from the .cs somehow?

I searched around to try to understand more about .axml files, so I understand that they can be used to specify a layout, instead of doing so in C# code. So I thought I could just delete the .axml file and rely on C# only--but then my Resource.String.whatever resources that I specified in Strings.xml won't work when referenced from my C# code.

Strings.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="helloButtonText">Say Hello</string>
<string name="helloLabelText">Hello Xamarin.Android</string>
</resources>

As mentioned, the .axml file references strings that no longer exist. How should I resolve that?

Was it helpful?

Solution

You probably have the following Button defined in the main.axml file:

<Button
    android:id="@+id/MyButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Hello" />

Replace the @string/Hello and you should be good to go. If you changed the string.xml then "@string/helloButtonText" might be the replacement you need, or simply "Say Hello".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top