Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 空指针,因为对象超出了警报对话框的范围?_Java_Android_Android Alertdialog - Fatal编程技术网

Java 空指针,因为对象超出了警报对话框的范围?

Java 空指针,因为对象超出了警报对话框的范围?,java,android,android-alertdialog,Java,Android,Android Alertdialog,出于某种原因,我得到了一个空指针异常,我想这是因为我的对象可能超出了警报对话框的范围?不过我可能错了 //private Lecture lecture; private LectureManager lectureManager; addwork.setPositiveButton("Add", new DialogInterface.OnClickListener() { @Override public void onClick(DialogI

出于某种原因,我得到了一个空指针异常,我想这是因为我的对象可能超出了警报对话框的范围?不过我可能错了

//private Lecture lecture;
private LectureManager lectureManager;


    addwork.setPositiveButton("Add", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            EditText eweight = (EditText) ((AlertDialog)dialog).findViewById(99);
            EditText emark = (EditText) ((AlertDialog)dialog).findViewById(100);
            String coursename = ecoursename.getText().toString();


            try {

            if ((eweight.getText().toString().trim().equals("")) || 
                (emark.getText().toString().trim().equals(""))) {

                throw new InvalidInputException();

                } else {

                Double tmark = Double.parseDouble(emark.getText().toString());
                Double tweight = Double.parseDouble(eweight.getText().toString());

                Work work = new Work(tmark, tweight);
                Lecture lecture = new Lecture(coursename);
                lecture.addEvent(work);
                lectureManager.addClass(lecture);
                }

我的空指针异常出现在“讲师管理器.addClass(讲师);”行,我不知道为什么。addClass是在类讲师管理器中定义的函数。我检索eView、emark和coursename信息的字段在警报对话框之外实例化,并且都是最终字段。提前谢谢

讲师从未被初始化过


private讲师管理员讲师管理员=新讲师管理员()

我认为您已经声明并且没有初始化讲师管理器变量。也让它成为最终的

private final LectureManager lectureManager;

//somewhere in code instantiate it 
lectureManger = new LectureManager();

// then your code 

希望这会有所帮助。

您确定
讲师管理器
已正确初始化吗?