Reputation: 521
I try to use fragments with AndroidAnnotations and maven. It worked with Android 4.0+ , but then I tried to make it work with Android 2.3.3 and I had to use the support-v4 maven library:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
My fragment is defined as:
<android.support.v4.app.Fragment android:id="@+id/myFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="com.bla.HeaderFragment_"/>
and My Activity extends FragmentActivity
I get this exception when I run the app:
.....
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.app.Fragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
at android.app.Activity.setContentView(Activity.java:1657)
at com.tagonsoft.codecamp.MainActivity_.setContentView(MainActivity_.java:46)
at com.tagonsoft.codecamp.MainActivity_.onCreate(MainActivity_.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: Fragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 22 more
Any idea why?
Upvotes: 1
Views: 3680
Reputation: 29436
Try <fragment>
tag and name
attribute for class name. Also, you've used class name as com.bla.HeaderFragment_
, seems like a typo.
<fragment android:id="@+id/myFragment"
android:name="com.bla.HeaderFragment_"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
More Examples here.
Upvotes: 2