0

I'm trying to hide a textView in my layout after I receive a result from an activity. I have a variable declaration - View lblEmptyList, which I instantiate in the onCreate:

lblEmptyList = findViewById(R.id.emptyList);

I tried this:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {

            case 1:
...
lblEmptyList.setVisibility(View.GONE);

But I'm getting an "Unreachable code" error. I tried to access it directly like that:

findViewById(R.id.emptyList).setVisibility(View.GONE);

I tried to use numeric values instead of View.GONE, but I keep getting this "Unreachable code" error. How do I fix it?

Igal
  • 5,833
  • 20
  • 74
  • 132
  • 2
    "Unreachable code" error means that your code will not be reached at runtime(it's a condition that is never true or something like that). it's nothing wrong with lblEmptyList.setVisibility(View.GONE) syntax. – Iulia Barbu Oct 24 '12 at 10:27
  • 1
    Look into your code. Do you have before setVisibility line something like throw Exception or return statement. – Agata Oct 24 '12 at 10:29
  • Got it! I moved this line before the rest of the code and then it worked just fine. Thank you both very much! – Igal Oct 24 '12 at 10:33

1 Answers1

0

The lblEmptyList.setVisibility(View.GONE); line had to be executed before the rest of the code.

Igal
  • 5,833
  • 20
  • 74
  • 132