2011-08-11 54 views
2
Syntax error on Token "Void", @ expected 
run cannot be resolved to a type 
Sytax error, insert enumBody to complete BlockStatement! 

这些都是3个错误,我在下面的脚本中获取。什么可能是问题?请注意,所有不需要的东西可能属于我的其他功能和东西。我有所有的进口过于现实:)我得到的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(); 
       } 
       } 

回答

3

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

就做这样代替。

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

当前你有一个方法中的方法。这就是所有令牌例外的原因。

+1

也应该启动线程:refreshAplle.start(); :) – Houcine

+0

Aww,我不能决定哪一个标记,但因为你说“开始线程”,那么你得到它:),因为我也错过了这一点:P – Elven

0

你运行在专有的中间进行,试试这个:

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的语法,用于扩展/实现声明的Class(在这种情况下为Thread)。

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

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

+1从我..不知道为什么你得到了-1。 – Kal

+0

感谢Kal。我得到了-1,因为我在错误的时候给出了一个答案(在它得到纠正之前),而布伦德尔回报了这个问题。 –

0

声明你的线程在括号

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(); 
       } 
       } 
      }; 
相关问题