0

誰かが私のコードの何が悪いのかを知ることができますか:(私は単純なアプリを作成することさえできません、それはそれをクラッシュさせ続けます。

アプリが実行するのは、ユーザーがボタンを押すと、テキストビューの色が赤に変わります。

public class MainActivity extends Activity {

public TextView tv1;
public Button bt1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bt1 = (Button)findViewById(R.id.button1);
    tv1 = (Button)findViewById(R.id.textView1);

    bt1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            tv1.setTextColor(Color.BLACK);
        }
    });

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Button" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button1"
    android:layout_toRightOf="@+id/button1"
    android:text="TextView" />

4

1 に答える 1

7
tv1 = (Button)findViewById(R.id.textView1);

と置換する

tv1 = (TextView)findViewById(R.id.textView1);
于 2012-11-21T16:21:27.653 に答える