我是一名java新手.我按照http://developer.android.com/resources/tutorials/views/hello-formstuff.html中的教程添加了一个按钮和OnClick处理程序,将教程代码复制到我的:
public class FormStuff extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setonClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(FormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
}
}
在Eclipse中,这会产生两个错误
Description Resource Path Location Type
The method setonClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){}) FormStuff.java /FormStuffExample/src/com/example/formstuffexample line 17 Java Problem
The type new DialogInterface.OnClickListener(){} must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int) FormStuff.java /FormStuffExample/src/com/example/formstuffexample line 17 Java Problem
我究竟做错了什么?谢谢!
解决方法:
完全基于错误消息……
您正在使用(隐式)错误的OnClickListener接口/类.看起来有两个,View.OnClickListener和DialogInterface.OnClickListener.
解决方案是完全限定您的匿名OnClickListener.
button.setonClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(FormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。