1

So I am new into Java and android development. I know basic Java (abstraction, inference, etc.) and I was going through one of the books on android development. I was supposed to build a small quiz app that has a text field and 3 buttons (true, false and next question). I have 2 classes, one is a controller and the other is a Model class. The app doesn't agree to run and the most I can make out from Logcat is something known as a null pointer exception. It would be great if anyone could help

I followed the instructions but had made small tweaks, but since that didn't work I simply just copy-pasted. Still the program isn't running

The controller class:

@Override
protected void onCreate(Bundle savedInstanceState) {
    Button mTrue;
    Button mFalse;

    TextView question=(TextView)findViewById(R.id.question_field);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TrueFalse[] ind= new  TrueFalse[]{new TrueFalse(R.string.q1, false),
            new TrueFalse(R.string.q2, true),
            new TrueFalse(R.string.q3, true),
            new TrueFalse(R.string.q4, true),
            new TrueFalse(R.string.q5, false)
    };

    int mIndex=0;

    int questions= ind[mIndex].getMquestion();
    question.setText(questions);}`

The model class:

public class TrueFalse {
private int mquestion;
private boolean mtruefalse;

public TrueFalse(int quest, boolean mtrue){
    mquestion= quest;
    mtruefalse= mtrue;
}

public int getMquestion() {
    return mquestion;
}

public void setMquestion(int mquestion) {
    this.mquestion = mquestion;
}

public boolean isMtruefalse() {
    return mtruefalse;
}

public void setMtruefalse(boolean mtruefalse) {
    this.mtruefalse = mtruefalse;
}

So the program was supposed to display the question in the text field as per the questions I preset on the strings.xml. I haven't hooked the next button as yet so that was nonfunctional. I have edited other attributes via the xml (which I don't think is a problem so I haven't put that up here).

Thanks

Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29
abacus143
  • 111
  • 2

0 Answers0