1

由于在我看来是一个奇怪的错误,我的应用程序在启动时不断崩溃。我已经包含了下面的 logcat 以及相关的布局,但是正如您所看到的,有一个由 class not found 的 class 异常引起的膨胀异常android.view.fragment。我没有使用兼容性片段(该应用程序不支持 pre-ICS),所以一切都在期待android.app.Fragment。我能找到的所有其他帖子都建议使用FragmentActivity,但这不是解决方案,因为我们不使用支持库。有没有人有任何见解?

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/locations"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- Some views here -->

    <!-- The line below is line 38 referenced in the LogCat -->
    <fragment
        android:id="@+id/ad_fragment"
        android:name="tenkiv.billing.AdFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        tools:layout="@layout/ad_fragment_view" />

</RelativeLayout>

和 LogCat 输出:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tenkiv.environment.application/com.tenkiv.environment.application.EnvironmentMainActivity}: android.view.InflateException: Binary XML file line #38: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.slidingmenu.lib.SlidingMenu.setMenu(SlidingMenu.java:384)
    at com.tenkiv.environment.application.EnvironmentMainActivity.onCreate(EnvironmentMainActivity.java:335)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.fragment" on path: /data/app/com.tenkiv.environment.application-2.apk
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
    ... 20 more
4

3 回答 3

1

我不确定是否尝试给出这样的完全限定名称

 <fragment android:id="@+id/fragmentDetails" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
class="tenkiv.billing.AdFragment"/>
于 2013-02-26T17:59:38.370 回答
0

请确保在您的 FragmentActivity 类中,您还从超类调用 onCreate 方法:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
....
}
于 2013-06-05T10:28:46.677 回答
0

这个问题可能是由一些愚蠢的事情引起的,比如错别字或奇怪的不可见字符被注入到你的 xml 标签中。就我而言,原因是我的“片段”开始标签中的拼写错误。我有“frsgment”,当然 Android Studio 没有举旗。我花了一段时间才弄清楚。不好!

于 2015-11-23T20:11:56.587 回答