2

I created a class where extends from ViewFlipper. When I try to instantiate on xml, it gives me this "error inflating class on xml"

FixedViewFlipper

public FixedViewFlipper(Context context)
{
    super(context);
}

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

Xml

<View class="com.touchcare.idealogix.android.FixedViewFlipper"
    android:id="@+id/flipperAdd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    >
</View>

Logcat

EDIT: I am using TabActivity at my MainActivity.

5
  • is your FixedViewFlipper class in that package that you specify in your view class xml?? im sorry but thats all I could guess from your code/logcat
    – Raykud
    Apr 11, 2012 at 0:37
  • package touchcare.idealogix.android; public class FixedViewFlipper extends ViewFlipper Apr 11, 2012 at 0:39
  • 3
    so you don't need the "com" on the beginning of your class definition in the xml Apr 11, 2012 at 0:44
  • @L7ColWinters is right, but if that doesnt solve the issue try adding the other constructor like: public FixedViewFlipper(Context context, AttributeSet attrs,int defStyle) { //something}
    – Raykud
    Apr 11, 2012 at 0:45
  • @Raykud I took a look at it but it seems that there is no defStyle for ViewFlipper, only Context and Context, AttributeSet. Apr 11, 2012 at 1:27

1 Answer 1

9

You just need view to not be capitalized -

<view 
    class="touchcare.idealogix.android.FixedViewFlipper"
    android:id="@+id/flipperAdd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    >
</view>

It's perfectly valid syntax and is how its done in a lot of the google apps

7
  • Eclipse autocomplete method says is fine with capitals :S
    – Raykud
    Apr 11, 2012 at 0:41
  • Still giving me the exception. Apr 11, 2012 at 0:44
  • @Raykud eclipse autocomplete is pointing you to <View/>, which refers to the Android class View. the <view class=""/> syntax points to a custom view of type class. Really <View /> is shorthand for <view class="com.android.view.View"/>
    – JRaymond
    Apr 11, 2012 at 0:45
  • oh, thanks for the info. I was in doubt since I remember I had this issue before and fixed it with underscore V but was wondering why eclipse was setting me upper.
    – Raykud
    Apr 11, 2012 at 0:49
  • this was helpful to me, I didn't know you specify the nodes class like this. Apr 11, 2012 at 0:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.