【问题标题】:I get 3 errors when I try to run timer尝试运行计时器时出现 3 个错误
【发布时间】:2011-10-25 01:09:49
【问题描述】:
Syntax error on Token "Void", @ expected
run cannot be resolved to a type
Sytax error, insert enumBody to complete BlockStatement!

这是我在以下脚本中遇到的 3 个错误。可能有什么问题?请注意,所有不需要的东西都可能属于我的其他功能和东西。实际上我也有所有的进口商品:)

import android.app.Activity;
import android.content.Intent;

public class MainStuff extends Activity {
    TextView tere;
    TextView dateatm;
    TextView timeatm;
    String nimi;
    String ip;
    protected static final int REFRESH = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        // Refresh after 5 sec... //
        Thread refresherAplle = new Thread();
            public void run(){
                try{
                    int refresherApple = 0;
                    while (refresherApple < 5000){
                        sleep(100);
                        refresherApple = refresherApple + 100;
                    }
                    startActivity(new Intent("viimane.voimalus.REFRESHER"));
                }
                finally{
                    finish();
                }
                }

【问题讨论】:

    标签: java android error-handling


    【解决方案1】:

    你的跑步已经知道了,试试这个:

     Thread refreshAplle = new Thread(){
            public void run(){
                try{
                      int refresherApple = 0;
                      while (refresherApple < 5000){
                         sleep(100);
                         refresherApple = refresherApple + 100;
                       }
                     startActivity(new Intent("viimane.voimalus.REFRESHER"));
                 } finally{
                    finish();
                 }
            }};
    

    【讨论】:

      【解决方案2】:

      它应该是new Thread() {,即一个左大括号,当用作new Class() { 时,它是用于创建扩展/实现声明的类(在本例中为线程)的新anonymous inner class 的语法。

      目前,您只需创建Thread() 的实例,因为您使用; 终止行,因此public void run() { } 在代码块中声明,这是非法的。要创建匿名类,请使用以下语法:

      Thread refresherAplle = new Thread() { //< notice this
          public void run() {
               ...
          }
      }
      

      【讨论】:

      • 谢谢卡尔。我得到 -1 是因为我在答案错误时(在它得到纠正之前)记下了答案,而 Blundell 回了恩。
      【解决方案3】:

      您的线程定义不正确。结尾的分号结束语句。

      改为这样做

      Thread refreshAplle = new Thread() {
          public void run() {
           ....
          }
      };
      

      目前你在方法中有一个方法。这就是所有令牌异常的原因。

      【讨论】:

      • 他也应该启动线程:refreshAplle.start(); :)
      • Aww,我无法决定要标记哪一个,但既然你说“开始线程”,那么你就明白了:),因为我也错过了这个:P
      【解决方案4】:

      在括号中声明你的线程

      Thread refresherApple = new Thread(){
                  public void run(){
                      try{
                          int refresherApple = 0;
                          while (refresherApple < 5000){
                              sleep(100);
                              refresherApple = refresherApple + 100;
                          }
                          startActivity(new Intent("viimane.voimalus.REFRESHER"));
                      }
                      finally{
                          finish();
                      }
                      }
                  };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-04
        • 2019-12-17
        • 2013-09-17
        • 2017-04-04
        相关资源
        最近更新 更多