Google Android“HelloFormStuff”教程出现Java错误

Google Android“HelloFormStuff”教程出现Java错误,第1张

概述我是一名java新手.我按照http://developer.android.comesourcesutorials/views/hello-formstuff.html中的教程添加了一个按钮和OnClick处理程序,将教程代码复制到我的:publicclassFormStuffextendsActivity{/**Calledwhentheactivityisfirstcreated.*/

我是一名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    TypeThe 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 ProblemThe 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();            }        });
总结

以上是内存溢出为你收集整理的Google Android“HelloFormStuff”教程出现Java错误全部内容,希望文章能够帮你解决Google Android“HelloFormStuff”教程出现Java错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115849.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存