1

I'm using Android Studio 1.0 RC 1 and I'm having trouble inflating a view class in xml file. I have a view file which extends GridView and which contains all 3 constructors:

package app.views;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class ImageSeGridView extends GridView {

    public ImageSeGridView(Context context) {
        super(context);
        init();
    }

    public ImageSeGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ImageSeGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        //....
    }
}

and I'm adding this view inside xml class:

<app.views.ImageSeGridView
        android:id="@+id/image_search_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

I'm not getting any complains at compile time, but at running I receive the following error:

android.view.InflateException: Binary XML file line #13: Error inflating class app.views.ImageSeGridView
        at android.view.LayoutInflater.createView(LayoutInflater.java:626)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:398)

and I do not know how to solve this issue. This does not occur when using IntelliJ IDEA 13 for example, happens only when using Android Studio.

1 Answer 1

1

I'm not sure if you are targeting 21, but this is what I have been doing lately.

public CustomView(Context context) {
    super(context);
    init();
}

public CustomView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

@TargetApi(21)
public CustomView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    init();
}

Quick Edit: Also, I use fully qualified package names for my elements - com.company.appname.views.widgets.customview etc in my layouts. I am not sure if that is the full extent of your package name

Sign up to request clarification or add additional context in comments.

1 Comment

Hey, I'm targeting 19 and I do not have a constructor with 4 parameters :( The package name is just informative, is not the real one I'm using it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.