菜鸟一枚,正在学习Android 开发,照着李刚的疯狂Android 讲义按部就班的一点点接触,里面的代码自己敲进去后总会或多或少有些错误,需要自己调试,今天分享一下最新遇到的。
在第三章,基于回调的事件监听器中,模拟运行时报错:Binary XML file line #8: Error inflating class org.crazyit.event.MyButton,表示使用回调按钮出错
查证之后是自己调用的包文件名不对,书上给出的代码是他默认的包文件名:
<<span style="color:#ff0000;">org.crazyit.event.</span>MyButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="单击我"
/>
而自己创建工程的包文件名是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<span style="color:#ff0000;">com.cuc604.chaptertheer</span>">
所以只需要把原代码中的包名改过来就可以正确执行了:
<<span style="background-color: rgb(255, 255, 255);"><span style="color:#00cccc;">com.cuc604.chaptertheer.MyButton</span></span>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="单击我"
/>