eclipse语法错误,插入“}”来完成classbody

时间:2013-11-26 09:09:27

标签: android

我是android编程的初学者。我只收到一条错误insert } to complete class body,它显示在箭头所示的行中,如下所示。请允许任何人在这方面帮助我。

以下是代码:

public class MainActivity extends Activity 
{
Button submit;
String temp;
DatePicker dt;
int day,month,year,choice;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton()
{
submit=(Button)findViewById(R.id.button1);
dt=(DatePicker)findViewById(R.id.datePicker1);
submit.setOnClickListener(new OnClickListener()
{                               //<--------------------here
public void onClick(View v)
{
day=dt.getDayOfMonth();
month=dt.getMonth();
year=dt.getYear();
choice=(day+month+year) % 5;
switch (choice)
{
................
................
}
Toast t= Toast.makeText(MainActivity.this,"You are"+temp,Toast.LENGTH_LONG);
t.show();
}
});
}
}    

2 个答案:

答案 0 :(得分:0)

为什么你有一个{而不是}?您要关闭方法addListenerOnButton吗?

答案 1 :(得分:0)

试试这个:

public class MainActivity extends Activity 
{
Button submit;
String temp;
DatePicker dt;
int day,month,year,choice;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton()
{
submit=(Button)findViewById(R.id.button1);
dt=(DatePicker)findViewById(R.id.datePicker1);
submit.setOnClickListener(new View.OnClickListener()//add View method
{                               //<--------------------here
public void onClick(View v)
{
day=dt.getDayOfMonth();
month=dt.getMonth();
year=dt.getYear();
choice=(day+month+year) % 5;
switch (choice)
{
................
................
}
Toast t= Toast.makeText(MainActivity.this,"You are"+temp,Toast.LENGTH_LONG);
t.show();
}
});
}
}

在我的代码中添加View.OnclickListener描述。