RuntimeException:无法启动活动:InflateException:二进制XML文件行#0:错误膨胀类片段

时间:2018-02-06 17:58:38

标签: java android android-layout android-fragments inflate-exception

我在崩溃报告中遇到此错误(我希望在此例外情况下解释所有内容)

Exception java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.packagetest/com.packagetest.MediaActivity}: 
android.view.InflateException: Binary XML file line #0: Error inflating 
class fragment
------
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2802)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2867)
android.app.ActivityThread.access$900 (ActivityThread.java:181)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1476)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:145)
android.app.ActivityThread.main (ActivityThread.java:6134)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run     (ZygoteInit.java:1399)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194)
arrow_drop_down


Caused by android.view.InflateException: Binary XML file line #0: Error inflating class fragment
------
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:770)
android.view.LayoutInflater.rInflate (LayoutInflater.java:813)
android.view.LayoutInflater.rInflate (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:511)
android.view.LayoutInflater.inflate (LayoutInflater.java:415)
android.view.LayoutInflater.inflate (LayoutInflater.java:366)
android.support.v7.app.l.b ()
android.support.v7.app.d.setContentView ()
**com.packagetest.MediaActivity.onCreate ()**
android.app.Activity.performCreate (Activity.java:6374)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2746)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2867)
android.app.ActivityThread.access$900 (ActivityThread.java:181)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1476)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:145)
android.app.ActivityThread.main (ActivityThread.java:6134)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1399)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194)
arrow_drop_down


Caused by android.os.BadParcelableException: ClassNotFoundException when     unmarshalling: asn
-------
android.os.Parcel.readParcelableCreator (Parcel.java:2289)
android.os.Parcel.readParcelable (Parcel.java:2239)
android.os.Parcel.readValue (Parcel.java:2146)
android.os.Parcel.readSparseArrayInternal (Parcel.java:2540)
android.os.Parcel.readSparseArray (Parcel.java:1868)
android.os.Parcel.readValue (Parcel.java:2203)
android.os.Parcel.readArrayMapInternal (Parcel.java:2479)
android.os.BaseBundle.unparcel (BaseBundle.java:221)
android.os.Bundle.getSparseParcelableArray (Bundle.java:871)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:836)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1060)
android.app.FragmentManagerImpl.onCreateView (FragmentManager.java:2156)
android.app.Activity.onCreateView (Activity.java:5636)
android.support.v4.a.e.onCreateView ()
android.support.v4.a.j.onCreateView ()
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:740)
android.view.LayoutInflater.rInflate (LayoutInflater.java:813)
android.view.LayoutInflater.rInflate (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:511)
android.view.LayoutInflater.inflate (LayoutInflater.java:415)
android.view.LayoutInflater.inflate (LayoutInflater.java:366)
android.support.v7.app.l.b ()
android.support.v7.app.d.setContentView ()
**com.packagetest.MediaActivity.onCreate ()**
android.app.Activity.performCreate (Activity.java:6374)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2746)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2867)
android.app.ActivityThread.access$900 (ActivityThread.java:181)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1476)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:145)
android.app.ActivityThread.main (ActivityThread.java:6134)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1399)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194)

因此,当您看到我的活动MediaActivity时,其布局包含自定义片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="ltr"
    android:id="@+id/linearLayoutPlayer">

    <fragment
        android:name="com.packagetest.MyPlayerFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/PlayerFragment"
        />

    <com.packagetest.MyRecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/recycleViewImages" />
</LinearLayout>

这是MediaActivity.onCreate:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Window window = getWindow();
    if (window != null) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    setContentView(R.layout.player);

    if (mPlayerFragment == null) {
        mPlayerFragment = (MyPlayerFragment) getFragmentManager().findFragmentById(R.id.PlayerFragment);
    } 

    if (mRecycleViewImages == null) {
        mRecycleViewImages = (MyRecyclerView) findViewById(R.id.recycleViewImages);
    }

    mPlayerFragment.initialize(DEVELOPER_KEY, new com.google.android.youtube.player.YouTubePlayer.OnInitializedListener() {
        @Override
        public void onInitializationSuccess(com.google.android.youtube.player.YouTubePlayer.Provider provider, com.google.android.youtube.player.YouTubePlayer youTubePlayer, boolean b) {}

        @Override
        public void onInitializationFailure(com.google.android.youtube.player.YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {}
    });

如您所见,我有一个名为MyRecyclerView的自定义recyclelview类和名为MyPlayerFragment的自定义片段。 因为错误提及错误膨胀类片段,我将添加其代码:

public class MyPlayerFragment extends YouTubePlayerFragment {
private FirebaseAnalytics mFirebaseAnalytics = null;   

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
}

@Override
public void onSaveInstanceState(Bundle bundle) {
    try {
        super.onSaveInstanceState(bundle);
    }
    catch (Exception e) {
        final Context context = getActivity();
        if (context == null) {
            return;
        }
        ((MediaActivity) (context)).finish();
    }
}

知道问题是什么?它从未发生在我的智能手机上

0 个答案:

没有答案