2016-11-12 35 views
1

我正在开发第一个android应用程序,它由一个百分比计算器组成。有两个文本框用于输入数字,一个文本视图,显示结果和一个按钮。当我运行该应用程序时,它给了我关于类的这些错误。我去了android.develpers网站查找按钮文档,似乎是正确的。但是,我不知道问题是什么。这是我实施的代码。开发第一个android应用程序的错误

//calculator variables 
TextView totalTxtView; 
EditText numberTxt; 
EditText percentTxt; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    //calculator code starts here ------------------// 

    //references 
    percentTxt = (EditText) findViewById(R.id.percentTxt); 
    numberTxt = (EditText) findViewById(R.id.numberTxt); 
    totalTxtView = (TextView) findViewById(R.id.totalTxtView); 

    Button button = (Button) findViewById(R.id.calcButton); 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // Do something in response to button click 
      float percent = float.parseFloat(percentTxt.getText().toString()); 
      float number = float.parseFloat(numberTxt.getText().toString()); 
      float result = numbrer * (percent * 0.10); 
      totalTxtView.setText(Float.toString(result)); 
     } 
    }); 

这是错误日志

Error:(41, 39) error: class expected 
Error:(41, 49) error: ';' expected 
Error:(41, 81) error: ';' expected 
Error:(42, 38) error: class expected 
Error:(42, 48) error: ';' expected 
Error:(42, 79) error: ';' expected 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 
Information:BUILD FAILED 
Information:Total time: 8.936 secs 
Information:7 errors 
Information:0 warnings 
Information:See complete output in console 
    enter code here 

任何帮助赞赏

+0

'float result = numbrer *(p​​ercent * 0.10);'---你在这行看起来有一个错字 – LiXie

回答

0

之前,你看太深入的调试,我相信你已经有了一个错字。

如果我正确理解您的逻辑,result应该是数字number作为由percentage给出的百分比。然后,你实际上应该更换:

float result = numbrer * (percent * 0.10); 

随着

float result = number * (percent * 0.01); 

如果没有,那么纠正你的错字到:

float result = number * (percent * 0.10); 

然后更新您的程序,并看看会发生什么。

+0

谢谢,这看起来像一个愚蠢的问题,但我试着穿过调试器,它指出我的课程错误。它完全把我扔了。调试器无法更准确地指出错误。纠正错误(错字)后仍然不起作用的 – miatech

+0

。运行应用程序时出现7个错误。他们都是。我是否需要导入任何课程? – miatech

相关问题