有人可以解释为什么我会收到这个错误吗?
Java.lang.ClassCastException: android.widget.Button cannot be cast to android.view.View$OnKeyListener
下面是java代码。我正在尝试按照教程进行操作,但无法开始。RAZR 模拟器只显示Unfortunately JimYamba quit working
. 错误来自 Eclipse LogCat。
package com.example.jimyamba;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.util.Log;;
public class MainActivity extends Activity implements OnClickListener{
Button buttonUpdate;
EditText editStatus;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.status);
buttonUpdate = (Button)findViewById(R.id.button_update);
editStatus = (EditText) findViewById(R.id.edit_status);
buttonUpdate.setOnKeyListener((OnKeyListener) this.buttonUpdate);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClick(View v){
String statusText = editStatus.getText().toString();
Log.d("StatusActivity","onClicked with text:" + statusText);
}
}