我不认为自己是初学者,但我的复制和粘贴让我迷失在自动生成的错误中。这是我的两难境地,如果我删除下面的注释,程序会意外崩溃;带有注释的程序显示得很好。
//////// Options.java /////
public class Options extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reclayout);
//Button STO = (Button)findViewById(R.id.StopBut);
//Button REC = (Button)findViewById(R.id.RecButton);
}
}
///////reclayout.xml/////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<Spinner
android:id="@+id/Spinner01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="Classes"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:lines="3"
android:id="@+id/DescriptionText"
android:text="Class Description"/>
<LinearLayout
android:layout_height="wrap_content"
android:id="@+id/ButtonLayout"
android:orientation="horizontal"
android:layout_width="fill_parent">
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="3"
android:id="@+id/RecButton"
android:focusableInTouchMode="true"
android:src="@drawable/rec"/>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="3"
android:id="@+id/PauseButton"
android:src="@drawable/pause"/>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="3"
droid:src="@drawable/stop"
android:id="@+id/StopBut"/></LinearLayout></LinearLayout>` 发布于 2010-11-14 10:40:40
它崩溃是因为您试图将ImageButton转换为Button。ImageButton不是Button的子类。在构造函数中,更改为
ImageButton STO = (ImageButton)findViewById(R.id.StopBut);
ImageButton REC = (ImageButton)findViewById(R.id.RecButton);
https://stackoverflow.com/questions/4175868
复制相似问题