我尝试使用带有 AndroidAnnotations 和 maven 的片段。它适用于 Android 4.0+ ,但后来我尝试使其适用于 Android 2.3.3 并且我不得不使用 support-v4 maven 库:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
我的片段定义为:
<android.support.v4.app.Fragment android:id="@+id/myFragment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
class="com.bla.HeaderFragment_"/>
我的活动扩展了 FragmentActivity
运行应用程序时出现此异常:
......
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
知道为什么吗?