因此,当我尝试在模拟器中运行代码时,会弹出应用程序背景,然后关闭并显示对话框,“不幸的是,Callisto已停止工作”
我不知道什么是错,除了它给了我一个空指针异常(第49行),但第49行什么都没有

XML格式



<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/callisto_heading" />

<Button
    android:id="@+id/bClasses"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Classes"
    android:layout_gravity="center"
    android:onClick=""
   />

<Button
    android:id="@+id/bSettings"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Settings"
    android:layout_gravity="center"
    android:onClick=""
 />

</LinearLayout>


爪哇
包android.callisto.com;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class CallistoActivity extends Activity {
/** Called when the activity is first created. */
 Button settings_button;
 Button classes_button;
 Button home_button;
 CheckBox notif_cb;
 CheckBox math_cb;
 CheckBox science_cb;
 CheckBox ss_cb;
 CheckBox english_cb;
 CheckBox language_cb;

 boolean notif,math,science,english,ss,language;




 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    //settings layout
    notif_cb = (CheckBox) findViewById(R.id.cbNotif);
    math_cb = (CheckBox) findViewById(R.id.cbMath);
    science_cb = (CheckBox) findViewById(R.id.cbScience);
    ss_cb = (CheckBox) findViewById(R.id.cbSS);
    english_cb = (CheckBox) findViewById(R.id.cbEnglish);
    language_cb = (CheckBox) findViewById(R.id.cbLang);
    home_button = (Button) findViewById(R.id.bHome);

    notif = true;
    math = true;
    science = true;
    english = true;
    ss = true;
    language = true;

    home_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            setContentView(R.layout.main);

        }
    });

        //notifications

    //main layout
    settings_button = (Button) findViewById(R.id.bSettings);
    classes_button = (Button) findViewById(R.id.bClasses);

    settings_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            setContentView(R.layout.settings);
        }
    });
}


}

仅供参考,该应用程序昨晚正在加载。。感谢您的帮助,请记住我是Android编程的新手。谢谢。

最佳答案

问题在这里

 home_button = (Button) findViewById(R.id.bHome);


在布局文件中没有bHome

关于java - 不幸的是,Callisto已停止工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13678027/

10-08 21:49