android - 识别使用缺少 AttributeSet 的 View 构造函数时的错误

标签 android eclipse android-layout android-view

作为一个不是初级程序员的初级 Android 程序员,我对我花了多少时间才意识到崩溃是由于省略使用将 AttributeSet 作为第二个参数并为在 XML 布局中定义的自定义 View 编写以下代码。

////////MyView.java////////

public class MyView extends View {

    public SimpleView(Context context) {
        super(context);
    }
    ...

}

我的问题是:我应该怎么做(在 Eclipse 中,ADT 变体)才能快速确定此错误?我相当仔细地查看 lint 消息,并希望这种习惯可以避免我为一个错误花费数小时。

手册当然明确指出,在 XML 布局中定义的自定义 View 应使用 View 构造函数的 (Context, AttributeSet) 变体,但回想起来,在任何级别进行编程都是无望的引用页面中的每一个细节都非常精确。

最佳答案

Graphical Layout应该有如下错误:

Custom view MyView is not using the 2- or 3-argument View constructors; XML attributes will not work

但我同意编译时错误会更好...

关于android - 识别使用缺少 AttributeSet 的 View 构造函数时的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13866814/

相关文章:

android - 如何在 android 相机中使用 anyFile.vsh 和 anyFile.fsh 赋予阴影效果?

安卓 : drop down a list of items without a spinner

android - 通过 Intent 额外通过电子邮件发送图像时发生 transactiontoolargeException

java - 蓝牙打印在不同设备上从 Socket 抛出 IOException

android - 在android中动态移动图像

python - 如何保留 Eclipse Pydev 项目的 PYTHONPATH 设置?

java - 尝试使用扫描仪时出现 "Cannot be resolved to a type"

java - 应用程序停止是因为按下了按钮?

java - 以不同的间隔多次重试代码段

android - 为什么我不能在 Eclipse 的工具栏中使用菜单 "run Android lint"中的 "Window"我可以运行它,可以吗?