0

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. The repeating function is updateTimeSlider(). When initiated via postDelayed, updateTimeSlider gives a "cannot resolve symbol" error (see image at the bottom of this post). updateTimeSlider() does not give that error when on a line by itself (also shown in the image).

(Note that updateTimeSlider() on the line by itself is not really how the code will go. It's just there to demonstrate that it works in that position.)

Can anyone help me understand how to correct the problem in the postDelayed line?

Several people have suggested that I just forgot to write the do in doUpdateTimeSlider. I did not forget. I wanted to execute updateTimeSlider (without the do), which does execute just fine and does not produce an error outside of postDelayed. updateTimeSlider is a C++ function used via JNI (Java Native Interface) using a statement at the bottom of this Java file that looks like this:

private native void updateTimeSlider();

The JNI aspect of things is working fine, and updateTimeSlider() is the method I am trying to execute, not doUpdateTimeSlider.

As an aside, I did try putting doUpdateTimeSlider in there, and it also results in an error: Variable doUpdateTimeSlider may not have been initialized.

not initialized error

I also don't see what good it would do me if I could execute doUpdateTimeSlider since there is no code in it to actually update the the timeSlider seekbar.

public class PlayActivity extends AppCompatActivity {

private static final String TAG = "PlayActivity";
boolean playing = false;
private int timeSliderInterval = 1000; // 1 second
private Handler timeSliderHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);

    final Runnable doUpdateTimeSlider = new Runnable() {
        @Override
        public void run() {
           timeSliderHandler.postDelayed(updateTimeSlider, timeSliderInterval);
           updateTimeSlider();
        }
    };

enter image description here

Community
  • 1
  • 1
user1147171
  • 1,213
  • 3
  • 14
  • 22
  • 4
    It is `doUpdateTimeSlider` instead of `updateTimeSlider` – ρяσѕρєя K Jan 01 '17 at 08:48
  • http://stackoverflow.com/questions/19931397/variable-r-might-not-have-been-initialized – trooper Jan 01 '17 at 19:08
  • 1
    I think you can resolve the "may not have been initialized" issue by making your `doUpdateTimeSlider` a member variable (vs local). The main difference between what your are showing us and what you are copying from is scope; your code is local within the scope of `onCreate`. – trooper Jan 01 '17 at 19:25
  • @trooper -- That did it! Thank you thank you thank you! If you want to make this an answer I will credit you. – user1147171 Jan 02 '17 at 01:22
  • @user1147171 - @trooper is right! We see what we saw. And we answers to what we saw. Anyways, Fixing that `may not have been initialized` doesn't have anything to do with this thread so, You can easily search about it. Another answer to this question(except the first one) : http://stackoverflow.com/a/35204885/4409113 – ʍѳђઽ૯ท Jan 02 '17 at 09:24

2 Answers2

1

As you can see here : https://stackoverflow.com/a/41413191/4409113

It is : doUpdateTimeSlider

final Runnable doUpdateTimeSlider = new Runnable() {
     @Override
     public void run() {
         timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
         updateTimeSlider();
     }
 };

Which @ρяσѕρєя K said the same.

Update:

To fix that may not have been initialized you can follow these links:

variable r might not have been initialized

"Variable example might not have been initialized" in anonymous class

So:

final Runnable etc = null;
    final Runnable doUpdateTimeSlider = new Runnable() {
        @Override
        public void run() {
            timeSliderHandler.postDelayed(etc, timeSliderInterval);
            updateTimeSlider();
        }
    };

This should work now!

Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • Thanks for your suggestion, @Mohsen. doUpdateTimeSlider also produces an error. But what good would it do me if I could execute doUpdateTimeSlider since there is no code in it to actually update the timeSlider seekbar? I added this to my question. – user1147171 Jan 01 '17 at 17:01
  • @user1147171 - I've edited/updated the answer. Please don't forget to read this answer too: http://stackoverflow.com/a/35204885/4409113 – ʍѳђઽ૯ท Jan 02 '17 at 09:31
1

You could replace:

timeSliderHandler.postDelayed(updateTimeSlider, timeSliderInterval);

with:

timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);

You forgot to write do in doUpdateTimeSlider.

ra1ned
  • 337
  • 5
  • 19
  • Thanks for your suggestion, but I did not forget. updateTimeSlider is what I was trying to execute. I also tried doUpdateTimeSlider and it also produces an error. I added all this to the question. – user1147171 Jan 01 '17 at 16:58
  • `doUpdateTimeSlider` is the name of your Runnable? then that is what you should be trying to `postDelayed` .. the other code you have in your `run` should do the actual updating, which is what I assume `updateTimeSlider` contains. – trooper Jan 01 '17 at 19:10