簡體   English   中英

未指定資源類型(在“ id”處,值為“ @ + id \\ st”)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM