语法错误,插入" EnumBody"去完成

时间:2014-03-18 04:26:05

标签: java android eclipse syntax-error

我正处于编码的中间,而我看到这个错误无处不在,我花了好几个小时但我无法弄明白,有人可以帮我解决它。

package com.example.good;

import android.app.Activity;
import android.os.Bundle;

public class SplasAct extends Activity {

@Override
protected void onCreate(Bundle sidra) {
    // TODO Auto-generated method stub
    super.onCreate(sidra);
    setContentView(R.layout.splash);

    Thread timer=new Thread();
    {
        public void run()   //error appears here
        {
        try{
                sleep(5000);
           }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
                 finally{
                Intent openStartingPoint=new Intent("com.example.good.MAINACTIVITY");
                startActivity(openStartingPoint);
                        }

        }

    };
    timer.start();

}
}

在错误定义上,它说,

Multiple markers at this line
- Syntax error, insert "enum Identifier" to complete 
 EnumHeaderName
- Syntax error, insert "EnumBody" to complete 
 BlockStatements
- Syntax error on token "void", @ expected

4 个答案:

答案 0 :(得分:1)

您正在此处实施匿名课程:

Thread timer=new Thread();{

所以你需要删除分号

Thread timer=new Thread() {

Semicolon终止可执行语句。所以你的类实现仍然没有挂钩并导致编译错误。

答案 1 :(得分:0)

;

中删除Thread timer=new Thread();

答案 2 :(得分:0)

package com.example.good;

import android.app.Activity;
import android.os.Bundle;

public class SplasAct extends Activity {

@Override
protected void onCreate(Bundle sidra) {
    // TODO Auto-generated method stub
    super.onCreate(sidra);
    setContentView(R.layout.splash);

    Thread timer=new Thread()
    {
        public void run()   //error appears here
        {
        try{
                sleep(5000);
           }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
                 finally{
                Intent openStartingPoint=new Intent("com.example.good.MAINACTIVITY");
                startActivity(openStartingPoint);
                        }

        }

    };
    timer.start();

}
}

尝试以上。并清楚地了解你在做什么阅读tutorial

答案 3 :(得分:0)

试试这种方式

public class MainActivity extends Activity {

TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /*
    final Handler hnd = new Handler()
    {
        public void handleMessage(android.os.Message msg) 
        {
            Bundle b = msg.getData();

            TextView tv = (TextView) findViewById(R.id.textView1);
            tv.setText(b.getString("mymessage"));
        };
    };*/

    tv = (TextView) findViewById(R.id.textView1);
    Button b1 = (Button)findViewById(R.id.button1);

    b1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

        // Implement Runnable Interface to override method run();



        // Create A thread from runnable and start it....

        Thread th = new Thread(new Demo());
        th.start();

        }
    });
}

class Demo implements Runnable
{
    public void run() {

        /*
        Message msg = hnd.obtainMessage();

        Bundle data = new Bundle();
        data.putString("mymessage", "Button Pressed From Thread");

        msg.setData(data);
        hnd.sendMessage(msg);
        */
        tv.setText("showed");
    }
}

}