why am I getting "cannot find symbol class textview" ?

  • Replies:25
  • OpenNot stickiedUnanswered
  • Forum posts: 12

Apr 24, 2016 7:09:28 PM via Website

I get this now
Error:(103, 17) error: local variable tick is accessed from within inner class; needs to be declared final

I pasted in your code.

  • Forum posts: 266

Apr 24, 2016 9:23:10 PM via Website

Make variable "tick" global or put declaration into timer's brackets. ;)

  • Forum posts: 12

Apr 25, 2016 2:10:53 AM via Website

the global route seems quite complicated, so I did this, putting variables within CountDownTimer's brackets, now no numbers show. :( I appreciate the help you are providing :)

public void mynumbers(View v) {
// TextView tv2 = (TextView) findViewById(R.id.textView2);
// tv2.setVisibility(View.VISIBLE);

   // String strI;
  //  int tick = 0;

    CountDownTimer timer = new CountDownTimer(2000, 25) {
        int tick = 0;
        String strI;
        TextView tv2 = (TextView) findViewById(R.id.textView2);

        @Override
        public void onTick(long l) {
            tick++;
           strI = String.valueOf(tick);
            tv2.setText(strI);
        }

        @Override
        public void onFinish() {
        }
    };
}
  • Forum posts: 266

Apr 25, 2016 2:18:07 PM via Website

This code should work:

public class MainActivity extends Activity {

    TextView tv2;
    int tick;
    String strI;

    CountDownTimer timer = new CountDownTimer(5000, 50) {

        @Override
        public void onTick(long l) {
            tick++;
            strI = Integer.toString(tick);
            tv2.setText(strI);
        }

        @Override
        public void onFinish() {
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv2 = (TextView) findViewById(R.id.textView2);
    }

    public void mynumbers(View v) {
        tick = 1;
        timer.start();
    }
}
  • Forum posts: 12

Apr 26, 2016 10:42:04 PM via Website

YES!!
working now. and thank you.
One thing, my line here is a bit different then yours, why?

public class MainActivity extends AppCompatActivity {

  • Forum posts: 266

Apr 26, 2016 11:33:58 PM via Website

AppCompatActivity is a safe to use backward compatibility class. It brings a single consistent ActionBar for all devices starting with API Level 7 (Android 2.1) and above. Android Studio uses AppCompatActivity by default.