[英]No resource type specified (at 'id' with value '@+id\st')
我是android編程的新手,我現在正嘗試制作一些按鈕 ,我使用以下代碼配置了這些按鈕:
MainActivity類:
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);
}
}
和XML布局 :
<?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>
而且我得到了語法錯誤:
error: Error: No resource type specified (at 'id' with value '@+id\st').
// and the same error with the other two buttons
提示: R class
已導入,並且可以從MainActivity
類訪問,但無法讀取R.id
您的代碼中有一些語法錯誤
首先使用Button
而不是button。
在ID后使用/代替\\。
<Button android:layout_width="100dp"
android:layout_height="50dp"
android:text="1st half"
android:id="@+id/st"
/>
您可以使用button
而是Button
。 區分大小寫。 並在android:id
通過/
替換\\
這是正確的代碼:
<Button android:layout_width="100dp"
android:layout_height="50dp"
android:text="1st half"
android:id="@+id/st"
/>
以此替換您的按鈕代碼,它應該可以工作
將button
替換為Button
,將android:id="@+id\\st"
替換為android:id="@+id/st"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.