0

This is my first Android/Java app. I am using the first answer here to try to initiate a repeating task, updating a seekbar ("timeSlider") to show progress as an audio file plays. Here is my code (eliminating a few irrelevant lines):

 private int timeSliderInterval = 1000; // 1 second
 private Handler timeSliderHandler;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_play);
     Intent intent = getIntent();
     Runnable doUpdateTimeSlider = new Runnable() {
         @Override
         public void run() {
             timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
             updateTimeSlider();
         }
     };

     void startUpdateTimeSlider() {
         doUpdateTimeSlider.run();
     }

     void stopUpdateTimeSlider() {
         timeSliderHandler.removeCallbacks(doUpdateTimeSlider);
     }

     final SeekBar timeSlider = (SeekBar) findViewById(R.id.timeSlider);

     if (timeSlider != null) {
         timeSliderHandler = new Handler();
         startUpdateTimeSlider();
     }

     @Override
     public void onDestroy() {
         super.onDestroy();
         stopUpdateTimeSlider();
     }

The project does not display in the emulator. Tooltips show these errors:

enter image description here

In addition, the startUpdateTimeSlider and stopUpdateTimeSlider functions are showing this error in tooltips:

enter image description here

Also, in the Run window, I'm getting:

emulator: emulator window was out of view and was recentered

emulator: ERROR: _factory_client_recv: Unknown camera factory query name in ' '

Any help will be greatly appreciated!

Community
  • 1
  • 1
user1147171
  • 1,213
  • 3
  • 14
  • 22

1 Answers1

0

First issue is self explained, you need to add final modifier.

final Runnable doUpdateTimeSlider = ...

Second one - move startUpdateTimerSlider() method, now its inside onCreate() method

Looks like you missed }:

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_play);
 Intent intent = getIntent();
 Runnable doUpdateTimeSlider = new Runnable() {
     @Override
     public void run() {
         timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
         updateTimeSlider();
     }
 };
}//<--------HERE

 void startUpdateTimeSlider() {
     doUpdateTimeSlider.run();
 }
Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
  • You pinpointed the problems reflected in these errors. Thank you! I'm not totally out of the woods yet, unfortunately. I've created a new question: http://stackoverflow.com/questions/41414330/android-java-cannot-resolve-in-postdelayed – user1147171 Jan 01 '17 at 08:48
  • 1
    First comment of the new question is a correct answer – Vasily Kabunov Jan 01 '17 at 08:51