Issue with page 165


#1

So, I’m trying to set the text on my mDateButton via:

mDateButton.setText(mCrime.getDate().toString());

But my app keeps crashing when I run it. I took the mDateButton.setText(mCrime.getDate().toString()); out of my code, ran the app, and it launched fine, however, the mDateButton widget did not display any text (for obvious reason, because i commented out the setText.getDate().toString()); line.)

I’ve got my getters and setters set up fine in Crime.java…for some reason, setText line keeps crashing my app. What gives?

[code] mDateButton = (Button)v.findViewById(R.id.crime_date);
mDateButton.setText(mCrime.getDate().toString());
mDateButton.setEnabled(false);

	    mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved);
	    mSolvedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
	        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
	            // Set the crime's solved property
	            mCrime.setSolved(isChecked);
	        }
	    });
	[/code]

Let me know if you need more code. Thanks in advance


#2

Alright so I am narrowing it down. the issue has to do with calling the getDate().toString()); part.

I tried running the app with

and it ran fine. What’s the deal with the getDate().toString());

After reading the error stack trace, it looks like there is a null pointer error when calling getDate().toString()

it makes sense in theory, to receive a null pointer, because I haven’t set the date to anything in Crime.java…

bah


#3

Haha, I figured it out.

didn’t write mDate = new Date();

in the Crime.java ctor.

Wow, writing everything out on this forum really helped me narrow stuffs down though.

noms (: