[英]Syntax error, insert “EnumBody” to complete
当我看到这个错误无处不在时,我正处于编码过程中,我花了几个小时,但我无法弄清楚,有人可以帮我解决这个错误。
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
您正在此处实现一个匿名类:
Thread timer=new Thread();{
所以你需要删除分号
Thread timer=new Thread() {
分号终止可执行语句。 因此,您的类实现仍然无法执行,并导致编译错误。
删除;
来自Thread timer=new Thread();
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();
}
}
试试上面。 并清楚地了解您在做什么,请阅读本教程
尝试这种方式
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");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.