Android project stopped working - can't find logical error
I am playing around with Android (extremely unfamiliar with it), and I am
having trouble understanding what went wrong here -
Data declarations in class-
//data
DateFormat dateFormat = null;
Date date = null;
String _date = null;
Random random;
Code inside function onCreate-
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get date and format it, then save it to a string
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
date = new Date();
//set the textview object as string object in R file
TextView text = (TextView) findViewById(R.string.quote);
//if the date has changed, change the quote randomly
random = new Random();
//
text.setText(_date.equals(dateFormat.format(date))?(CharSequence)quotes[(random.nextInt(quotes.length)+1)]:(CharSequence)findViewById(R.string.quote));
//set date as new date
_date = dateFormat.format(date);
I know that's a really long and annoying ternary operation, and I feel
that it may be why when I try to open the app in the emulator it stops
working.
_date.equals(dateFormat.format(date)) ? (CharSequence)
quotes[(random.nextInt(quotes.length) + 1)] :(CharSequence)
findViewById(R.string.quote)
Any ideas as to what's going wrong?
No comments:
Post a Comment