0

I'm new at android programming, I'm now trying to make some buttons, I configured these buttons using the following code:

The MainActivity class :

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */

    Button st,nd,center;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        st = (Button)findViewById(R.id.st);
        st = (Button)findViewById(R.id.center);
        st = (Button)findViewById(R.id.nd);


    }
}

and the XML Layout:

<?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"
    android:background="@drawable/background"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Hello from animation!!"
    />
<button android:layout_width="100dp"
android:layout_height="50dp"
android:text="1st half"
android:id="@+id\st"
/>
// and the other two points defined the same way
</LinearLayout>

And i got that syntax error:

error: Error: No resource type specified (at 'id' with value '@+id\st').
// and the same error with the other two buttons

HINT: The R class is imported and accessible from the MainActivity class but it can't read R.id.

4

3 回答 3

2

there are some syntax errors in your code

first use Button instead of button.

use / instead of \ after id.

<Button android:layout_width="100dp"
android:layout_height="50dp"
android:text="1st half"
android:id="@+id/st"
/>
于 2013-11-13T09:56:15.540 回答
1

You use button instead Button. It is case sensitive. And at android:id replace the \ through /

This is the correct code:

<Button android:layout_width="100dp"
    android:layout_height="50dp"
    android:text="1st half"
    android:id="@+id/st"
/>

Replace your button code with this and it should work

于 2013-11-13T09:54:55.887 回答
0

Replace button with Button and android:id="@+id\st" with android:id="@+id/st"

于 2013-11-13T09:50:04.830 回答