Android编译错误:找不到符号类Textview

时间:2016-07-16 14:04:13

标签: android compilation

我在Android测试应用开发期间运行代码时遇到错误。

Error:(20, 9) error: cannot find symbol class Textview
Error:(20, 38) error: cannot find symbol method findViewByID(int)
Error:(22, 35) error: cannot find symbol method FindviewbyId(int)
Error:(24, 9) error: cannot find symbol class string
Error:(26, 9) error: cannot find symbol variable brnads

FindBeerActivity中的源代码如下所示。

package com.hfad.beeradviser;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Spinner;
import android.widget.TextView;

public class FindBeerActivity extends Activity {

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

//Call when the button gets clicked
public void onClickFindBeer(View view) {
    //get a reference to the Textview
    Textview brands = (TextView) findViewByID(R.id.brands) ;
    //get a reference to the Spinner
    Spinner color = (Spinner) FindviewbyId(R.id.color);
    //Get the selected item in the Spinner
    string beerType = String.valueOf(color.getSelectedItem());
    //Display the selected item
    brnads.setText(beerType);
  }
}

你能帮我解决这个错误吗?

1 个答案:

答案 0 :(得分:0)

你只是错误地重命名了东西。替换为:

//Call when the button gets clicked
public void onClickFindBeer(View view) {
    //get a reference to the Textview
    TextView brands = (TextView) findViewById(R.id.brands) ;
    //get a reference to the Spinner
    Spinner color = (Spinner) findViewById(R.id.color);
    //Get the selected item in the Spinner
    String beerType = String.valueOf(color.getSelectedItem());
    //Display the selected item
    brands.setText(beerType);
}