Don't you just love it when some part of your app just suddenly and magically STOPS working all of a sudden?
Our submitter David sure does (not). While working on his Android app, much to his surprise, he noticed that after one build, it wasn't displaying pop-up toast style notifications.
He was positively stymied. It's not like this functionality is weird and custom with black magic UI coding behind it. No, this is something basic and ancient that one would normally expect to just work. However, upon checking the function behind the notifications below, the reason became immediately clear. At some point, David had accidentally pasted a URL in the middle of the function.
public void showToast(final String msg) {
// Show small piece of text at the bottom of screen
runOnUiThread(new Runnable() {
public void run() {
CharSequence text = msg;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(con, text, duration);
http://example.com/ toast.show();
Log.d("toast", msg);
}
});
}
Normally, one would expect that a mistake like this would have set off alarms at compilation time but in this case, it's actually valid. In Java, the "http:" acts as a labeled statement, which is logically similar to a "goto" statement in other languages, and the // which follows it commented out the rest of the line which contains the bit of code that actually shows the toast pop-up.
Thankfully this sort of misery only applies to Java...right?