Android Java:“无法解析";在postDelayed [英] Android Java: "Cannot resolve" in postDelayed

查看:63
本文介绍了Android Java:“无法解析";在postDelayed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

我也看不出如果我可以执行 doUpdateTimeSlider 会对我有什么好处,因为其中没有代码可以实际更新 timeSlider 搜寻栏./p>

 公共类PlayActivity扩展了AppCompatActivity {私有静态最终String TAG ="PlayActivity";布尔播放=假;private int timeSliderInterval = 1000;//1秒私有处理程序timeSliderHandler;@Override受保护的void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_play);最后的Runnable doUpdateTimeSlider = new Runnable(){@Override公共无效run(){timeSliderHandler.postDelayed(updateTimeSlider,timeSliderInterval);updateTimeSlider();}}; 

解决方案

如您在此处看到的: https://stackoverflow.com/a/41413191/4409113

它是: doUpdateTimeSlider

  final Runnable doUpdateTimeSlider = new Runnable(){@Override公共无效run(){timeSliderHandler.postDelayed(doUpdateTimeSlider,timeSliderInterval);updateTimeSlider();}}; 

@ρяσsρєяK说的也是一样.

更新:

要解决可能尚未初始化的问题,您可以点击以下链接:

变量r可能尚未初始化

可能未初始化变量示例";在匿名课程中

所以:

  final Runnable等= null;最后的Runnable doUpdateTimeSlider = new Runnable(){@Override公共无效run(){timeSliderHandler.postDelayed(etc,timeSliderInterval);updateTimeSlider();}}; 

现在应该可以使用!

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.

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();
        }
    };

解决方案

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!

这篇关于Android Java:“无法解析";在postDelayed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆