小编jbl*_*tle的帖子

无法解析方法setText(java.lang.String)

我已经看过类似于我得到的错误的其他问题,但我似乎无法在这里弄清楚这个问题.我要做的就是单击一个按钮并更改TextView的文本.

我的代码如下:

public class FindBeerActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_find_beer);
}
//call when the user clicks the button
public void onClickFindBeer(View view) {

    //Get a reference to the TextView
    View 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 beers. This is where the error is
    brands.setText(beerType);

  }
}
Run Code Online (Sandbox Code Playgroud)

和XML

 <TextView
    android:id="@+id/brands"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/find_beer" …
Run Code Online (Sandbox Code Playgroud)

java android android-studio

5
推荐指数
1
解决办法
8480
查看次数

标签 统计

android ×1

android-studio ×1

java ×1