因此,当我尝试在模拟器中运行我的代码时,应用程序后台弹出然后关闭给我对话框,“不幸的是,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>
Java包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 编程新手。谢谢你。