runOnUiThread(new Runnable() { 标点符号(令牌)问题
不知怎的,它不起作用,根据我的说法,应该是这样的:
public void Splash(){
Timer timer= new Timer();
timer.schedule(new TimerTask(){
MexGame.this.runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);
} //Closes run()
}); //Closes runOnUiThread((){})
},SplashTime); //Closes the Timeratask((){})
} //closes Splash()
有人知道我错过了什么吗?
正式评论 我知道这个问题很愚蠢,或者也许我正在做一些不可能的事情,但我尝试了所有合乎逻辑的可能性。所以可能错过了一些东西或者我正在尝试做一些不可能的事情。 你能帮我一下吗? 我正在尝试使用以下代码,但这会带来令牌问题:
Timer timer= new Timer();
timer.schedule(new TimerTask(){
runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
});}
},SplashTime);
如果我阻止 runOnUiThread 它会崩溃,因为我试图从另一个线程调整 UI,但至少没有令牌问题,有人知道吗?
Timer timer= new Timer();
timer.schedule(new TimerTask(){
// runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
// });}
},SplashTime);
Somehow it doesn't work, according to me it should be this:
public void Splash(){
Timer timer= new Timer();
timer.schedule(new TimerTask(){
MexGame.this.runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);
} //Closes run()
}); //Closes runOnUiThread((){})
},SplashTime); //Closes the Timeratask((){})
} //closes Splash()
Anybody any idea where I'm missing something?
FORMAL COMMENT
I know silly issue, or maybe I'm doing something impossible, but I tried all the logical possibilities. So probably missing something or I'm trying to do something that is not possible.
Can you please help me out.
I'm trying to use the following code, but that gives token issues:
Timer timer= new Timer();
timer.schedule(new TimerTask(){
runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
});}
},SplashTime);
If I block out the runOnUiThread it crashes since I'm trying to adapt the UI from another thread, but at least no token issue, anybody any idea?:
Timer timer= new Timer();
timer.schedule(new TimerTask(){
// runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
// });}
},SplashTime);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TimerTask 和 Runnable 都要求您实现 run 方法,因此您需要两个
run
方法。此外,如果将 Runnable 的构造与 TimerTask 的构造分开,您的代码将更易于阅读。
Both the TimerTask and the Runnable require you to implement a run method, so you'll need two
run
methods.Also your code will be more easy to read if you separate the construction of the Runnable from the construction of the TimerTask.
SplashTime
之前有多余的“}”。您注释了一个开头“{”和两个结尾“}”,因此您的原始代码有一个不需要的“}”。You have excess "}" before
SplashTime
. You've commented one openning "{" and two closing "}", so your original code have one unrequired "}".