android 问题,今天编的一个小程序,一直提示Syntax error, insert ";" to complete FieldDeclaration
packagecom.text;importjava.text.DecimalFormat;importandroid.app.Activity;importandroi...
package com.text;
import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class WuActivity extends Activity {
/** Called when the activity is first created. */
private Button button_calc;
private EditText field_personNum;
private EditText field_zz;
private TextView view_result;
private TextView view_suggest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setListener();
}
private void findViews(){
button_calc=(Button)findViewById(R.id.submit);
field_zz=(EditText)findViewById(R.id.zz);
field_personNum=(EditText)findViewById(R.id.personNum);
view_result=(TextView)findViewById(R.id.result);
view_suggest=(TextView)findViewById(R.id.suggest);
}
private void setListener(){
button_calc.setOnClickListener(calcFoxWAR);
}
private OnClickListener calcFoxWAR=
new OnClickListener(){
public void onClick(View v){
try{
DecimalFormat nf=new DecimalFormat("0.00");
double personNum=Double.parseDouble(field_personNum.getText().toString());
double zz=Double.parseDouble(field_zz.getText().toString());
double FoxWAR=zz/personNum;
view_result.setText("你的计算单兵装备值是"+nf.format(FoxWAR));
if(FoxWAR>25){
view_suggest.setText(R.string.advice_DL);
}else if(FoxWAR<20){
view_suggest.setText(R.string.advice_SL);
}else{
view_suggest.setText(R.string.advice_average);
}
openOptionsDialog();
} catch(Exception e){
Toast.makeText(WuActivity.this, "这里只能输入数字!!", Toast.LENGTH_SHORT).show();
}
}
};
private void openOptionsDialog() {
// TODO Auto-generated method stub
//new AlertDialog.Builder(this).setTitle(R.string.about_title).setMessage(R.string.about_msg)
//.setPositiveButton("确认", new DialogInterface.OnClickListener() {
//public void onClick(DialogInterface dialog, int which) {
//// TODO Auto-generated method stub
//}
//}).show();
Toast.makeText(WuActivity.this,"FoxWAR 计算器",Toast.LENGTH_SHORT).show();
}
} 展开
import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class WuActivity extends Activity {
/** Called when the activity is first created. */
private Button button_calc;
private EditText field_personNum;
private EditText field_zz;
private TextView view_result;
private TextView view_suggest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setListener();
}
private void findViews(){
button_calc=(Button)findViewById(R.id.submit);
field_zz=(EditText)findViewById(R.id.zz);
field_personNum=(EditText)findViewById(R.id.personNum);
view_result=(TextView)findViewById(R.id.result);
view_suggest=(TextView)findViewById(R.id.suggest);
}
private void setListener(){
button_calc.setOnClickListener(calcFoxWAR);
}
private OnClickListener calcFoxWAR=
new OnClickListener(){
public void onClick(View v){
try{
DecimalFormat nf=new DecimalFormat("0.00");
double personNum=Double.parseDouble(field_personNum.getText().toString());
double zz=Double.parseDouble(field_zz.getText().toString());
double FoxWAR=zz/personNum;
view_result.setText("你的计算单兵装备值是"+nf.format(FoxWAR));
if(FoxWAR>25){
view_suggest.setText(R.string.advice_DL);
}else if(FoxWAR<20){
view_suggest.setText(R.string.advice_SL);
}else{
view_suggest.setText(R.string.advice_average);
}
openOptionsDialog();
} catch(Exception e){
Toast.makeText(WuActivity.this, "这里只能输入数字!!", Toast.LENGTH_SHORT).show();
}
}
};
private void openOptionsDialog() {
// TODO Auto-generated method stub
//new AlertDialog.Builder(this).setTitle(R.string.about_title).setMessage(R.string.about_msg)
//.setPositiveButton("确认", new DialogInterface.OnClickListener() {
//public void onClick(DialogInterface dialog, int which) {
//// TODO Auto-generated method stub
//}
//}).show();
Toast.makeText(WuActivity.this,"FoxWAR 计算器",Toast.LENGTH_SHORT).show();
}
} 展开
2个回答
展开全部
字面的上错误提示的意思是:“语法错误,插入“;”去完成声明”,也就是说你哪个地方少了冒号,或者冒号的写法用了汉字输入法,你找找看。这种问题你直接在错误信息里,找到你的包的那句,双击就点进去你代码里面,就是那一行出错了。
追答
Toast.makeText(WuActivity.this, "这里只能输入数字!!", Toast.LENGTH_SHORT).show();
}
}
};这个冒号看看什么地方对齐的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询