Reputation: 3880
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.
Upvotes: 1
Views: 3641
Reputation: 553
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
Upvotes: 1