Android 第一行代码学习报错整理

来源:互联网 发布:阿里云havip怎么开通 编辑:程序博客网 时间:2024/05/24 11:13

2.1 添加Toast  提示有错:

1、The type new View.OnClickListener(){} must implement the inherited abstract method View.OnClickListener.onClick(View)

2、android:View cannot be resolved to a type


You should import it. If you are using Eclipse, press Ctrl+Shift+o.

"import Android.view.View"

然后点击了自动修复选项,不再报错,但运行无法显示Toast内容,去掉自动修复,报错为:

1、The type new View.OnClickListener(){} must implement the inherited abstract method View.OnClickListener.onClick(View)

2、Multiple markers at this line
 - The method OnClick(View) of type new View.OnClickListener(){} must override or implement a supertype method
 - The method OnClick(View) from the type new View.OnClickListener(){} is never used locally

最后在老管的指导下,将xml布局文件中添加  android:onClick="click" ,如下:

程序就不再报错,并且可以正常运行了。


2.2 添加Menu

报错:menu cannot be resolved to a variable

书上说,inflate()方法接受两个参数,第一个用于指定通过哪一个资源文件来创建菜单,第二个用于指定将菜单项添加到哪一个Menu对象中,这里直接使用了onCreateOptionsMenu()方法中传入的menu参数。


有关Android中菜单的更多内容可参考:  http://www.cnblogs.com/qingblog/archive/2012/06/08/2541709.html



0 0
原创粉丝点击