java - 不幸的是,卡里斯托已经停止工作

标签 java android xml eclipse nullpointerexception

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

最佳答案

问题就在这里

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

布局文件中没有bHome

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

相关文章:

java - AsyncTask 更好的通信协议(protocol)

xml - Hadoop - 使用 XPath 在 XML 节点上进行 PIG 循环

android - 每个 fragment 的工具栏导致内存问题

Java一次性定时器终止主要功能

java - 如何在 Maven pom.xml 中定义属性并从命令行传递参数?

使用 Nodejs、Angular、Karma、Jasmine 和 Maven 的 Java 动态 Web 项目

android - 为什么将 'debuggable true' 添加到我的 Android 版本构建类型会消除神秘错误?

xml - 模糊搜索FIELD azure中的全局列表

java - 如何解析类型定义为 XSD :any 的 XML

java - HQL - 内连接错误