I'm creating a boolean array pre-populated with false values. I understand that I don't have to declare false values as they are automatically assigned however I've been trying different methods to try and solve the problem.
package com.bignerdranch.android.geoquiz;
import android.app.ActionBar;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuizActivity extends ActionBarActivity {
private static final String TAG = "QuizActivity";
private static final String KEY_INDEX = "index";
private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private Button mCheatButton;
private TextView mQuestionTextView;
private TrueFalse[] mQuestionBank = new TrueFalse[] {
new TrueFalse(R.string.question_oceans, true),
new TrueFalse(R.string.question_mideast, false),
new TrueFalse(R.string.question_africa, false),
new TrueFalse(R.string.question_americas, true),
new TrueFalse(R.string.question_asia, true),
};
private int mCurrentIndex = 0;
private boolean mIsCheater;
private boolean[] mCheatedAnswers = new boolean[] {false, false, false, false, false};
I have a breakpoint on the last line, and when the program breaks here the mCheatedAnswers is instantiated as null. I don't understand why as I have given it a boolean array - does anyone know why this could be?
The previous variables all have the correct values assigned to them when I check them in the debug mode.
If you've put the breakpoint on the last line, then when it hits, the assignment hasn't executed yet.
If you put a breakpoint in the constructor body - or just step over the line - you'll find the value is assigned appropriately. (It would be simpler just to use new boolean[5]
, mind you... false
is the default value... Mind you, it would probably be better to have a class which included the question and whether or not the user cheated. Then you'd only need one collection.)
See more on this question at Stackoverflow