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