I'm working on my first Android app coming from 2 years of C++ from school.
The code looks like this:
double total = 100000000000L;
for(long i = 0L; i < diff; i++) {
total += 1.8;
}
countView.setText(NumberFormat.getInstance().format(total));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (total += 1.8 < 200000000000L) {
handler.postDelayed(this, 1000L);
return;
}
handler.removeCallbacks(this);
}
}, 1000L);
In C++, I'd be able to reuse the total variable no problem - it's in the same scope. But in Java I'm getting an error message that I'm attempting to access an inner class. Trying to declare total as public or static gives the error that the modifier isn't allowed here.
Why can I use total right below where I declare but not several lines down?