Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Android 多构造函数和空值_Android_Constructor - Fatal编程技术网

Android 多构造函数和空值

Android 多构造函数和空值,android,constructor,Android,Constructor,1:从一节课开始测验课: Med.setQuiz(new Quiz(Cat, null)); 问答课: public Quiz(final String category, TextView outputTxt) { MyTxt = outputTxt; StartAct(category); } 2:从另一个班级开始测验课程: Quiz MyNewQ = new Quiz(null, Txt); 首先:我开始上课,用StartAct(类别)设置一

1:从一节课开始测验课:

Med.setQuiz(new Quiz(Cat, null));
问答课:

public Quiz(final String category, TextView outputTxt) {
        MyTxt = outputTxt; 
            StartAct(category);
}
2:从另一个班级开始测验课程:

Quiz MyNewQ = new Quiz(null, Txt);
首先:我开始上课,用StartAct(类别)设置一些值

然后我再次使用了类:测验(null,Txt)但是当我使用它时,StartAct值设置为null

但是我想使用我在第一堂课[quick(Cat,null)]中设置的值


如何执行此操作?

您可以使用如下静态值:

public class Quiz{

    private static String category;

    public Quiz(final String category, TextView outputTxt) {

            // check category is not null or empty, don't set if it is
            // which means that we must call the constructor with a valid category
            // the first time or perhaps set a default value
            if(category!=null && !category.equals("")){
                Quiz.category = category;
            }
            MyTxt = outputTxt; 
            StartAct(Quiz.category);

    }
}