Java – The issue in the first android/java tutorial

The issue in the first android/java tutorial… here is a solution to the problem.

The issue in the first android/java tutorial

I’m just starting to try Eclipse, which uses Java for Android programming. In fact, I’m working on the first basic sample application in the developer.android.com tutorial. I have the following activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=". MainActivity" >
    android:orientation="horizontal" >

<EditText android:id="@+id/edit_message"
       android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

android:text="@string/button_send"
    android:onClick="sendMessage" />

</LinearLayout>

and the following strings.xml

<?xml version="1.0" encoding="utf-8"? >
<resources>

<string name="app_name">My First App2</string>
    <string name="edit_message">Enter a message</string>
    <string name="button_send">Send</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="title_activity_display_message">My Message</string>
    <string name="hello_world">Hello world!</string>

</resources>

As you can see, I have an button_send string and an edit_message string in strings.xml, both of which are referenced in activity_main.xml. However, the build produces the error “No resource found matching the given name (at ‘text’, the value is ‘@string/button_send’)”. Any ideas?

Solution

Here are some ideas:

  1. Make sure strings.xml is in your res/values folder.
  2. Clean up your project (Project-> Cleanup). This will delete your gen folder and rebuild it. Whenever you make changes to a resource, it’s a good idea to clean up the project and rebuild all R.id.* values.

Edit:

You can also go to the eclipse GUI of the XML file and right-click the button. Click Edit Text, which will display your string value. You should be able to see the button_send. If you don’t, there’s something wrong with your strings.xml.

Related Problems and Solutions