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