Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android.view.InflateException:XML布局中的二进制XML文件行_Android_Android Xml_Android Custom View - Fatal编程技术网

android.view.InflateException:XML布局中的二进制XML文件行

android.view.InflateException:XML布局中的二进制XML文件行,android,android-xml,android-custom-view,Android,Android Xml,Android Custom View,这是我的密码。当我膨胀视图时,显示名为android.view.InflateException的异常:我的MainActivity类中的二进制XML行#8。也会使应用程序崩溃, 如果代码有错误,请帮助我 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layou

这是我的密码。当我膨胀视图时,显示名为android.view.InflateException的异常:我的MainActivity类中的二进制XML行#8。也会使应用程序崩溃, 如果代码有错误,请帮助我

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/ic_launcher">

    <com.example.newscratch.PaintView
        android:layout_gravity="center"
        android:id="@+id/img1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

您必须在
PaintView
类中再定义两个构造函数

    public PaintView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }

    public PaintView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

没有stacktrace,这不容易

乍一看:PaintView类中缺少适当的构造函数

添加具有此签名的构造函数:

public PaintView(Context context, AttributeSet attrs, int defStyle){
     super(...);
     ...
}

我认为您忘记实现“XML构造函数”。您应该添加:

public PaintView((Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);
}

有关更多信息,请参阅。

请发布异常堆栈跟踪,包括嵌套的“由”异常。您是否为要开发的内容添加了适当的库?如果是,请尝试清理项目,否则重新启动eclipse。如果没有,则正确检查两次并添加。
public PaintView(Context context, AttributeSet attrs, int defStyle){
     super(...);
     ...
}
public PaintView((Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);
}