繁体   English   中英

Android视图膨胀异常?

[英]Android view Inflate exception?

我有一小段xml代码,可按如下方式扩展视图:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:elektromotus="http://schemas.android.com/apk/res/eu.elektromotus"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<eu.elektromotus.widget.DashboardView
    android:id="@+id/dashboardView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/dashboard_back"/>

<ImageButton
    android:id="@+id/error_notifier"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/notifier_bg"
    android:contentDescription="@string/msg_error_notifier"
    android:src="@drawable/ic_stat_alert"
    android:visibility="invisible" />
</merge>

当我运行我的应用程序时,我的日志中出现以下错误:

android.view.inflateException: Binary XML line #8: Error inflating class eu.elektromotus.widget.DashBoardView

我在执行中做错了吗? 还是我的问题在别处?

问题可能是您的自定义DashboardView类构造函数没有调用正确的super constructor View。 当您使用XML引用自定义视图时,类构造函数应将AttributeSet连同此类上下文一起传递。

public class DashboardView extends View {
  public DashboardView(Context context, AttributeSet attrs) {
      super(context, attrs);
    }
 }

另外,请确保XML中的自定义类包名称正确

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM