初学Android,遇到很多问题我照着书上写了一个CheckBox的程序,在Eclipse上没有编译错误,但是在模拟器上运行的时候出错(见附图)我已经找了好久了,都没有找到错误在哪
以下是代码:
这是layout文件夹下的main.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"
    >
<ChackBox android:id="@+id/tabCBX1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="CheckBox1">
    </ChackBox>
    <ChackBox android:id="@+id/tabCBX2"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="CheckBox2">
    </ChackBox>
</LinearLayout>
这是src文件夹下包里的java文件package android.checkbox;import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;public class MainActivity extends Activity {

CheckBox mCheckBox1;
CheckBox mCheckBox2;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mCheckBox1 = (CheckBox) findViewById(R.id.tabCBX1);
        mCheckBox2 = (CheckBox) findViewById(R.id.tabCBX2);
        
        mCheckBox1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(mCheckBox1.isChecked())
{
Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT);
}
}
});
        mCheckBox2.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(mCheckBox2.isChecked())
{
Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT);
}
}
});

    }
}
至于其他文件,因为这个代码是由hello android工程改的,所以其他部分不变,我就不贴出来了。希望前辈解答一下。
真的很郁闷啊,这么简单的功能都实现不了~

解决方案 »

  1.   

    1.切换到DDMS视图,点击“Force close”,看看哪句抛异常了
    2.AndroidManifest.xml配置是否正确
    3.Toast不对
    Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT);
    应该是
    Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
      

  2.   

    嗯,把Toast改了,但是还是不行
    切换到DDMS视图下,点击ForceClose也没有发现异常~
    AndroidManifest.xml完全和例子程序一样但是例子程序能过,但是我的过不了~
      

  3.   

    你的XML文件了的标签ChackBox改成CheckBox
      

  4.   

    Toast toast=Toast.makeText(mainActivity.this, box.getText().toString(), Toast.LENGTH_LONG);
    toast.show();