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
.
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"
/>
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
将button
替换为Button
,将android:id="@+id\\st"
替换为android:id="@+id/st"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.