android.view.InflateException错误膨胀类片段,二进制XML文件行#1?

时间:2016-07-13 17:25:55

标签: java android xml android-fragments parcel

Android项目出现InflateException错误。

这是Android Studio Android Monitor的错误:

  

---------崩溃的开始   07-14 00:03:23.801 13726-13726 / com.example.romi.parcelablecreatortest E / AndroidRuntime:FATAL EXCEPTION:main                                                                                           处理:com.example.romi.parcelablecreatortest,PID:13726                                                                                           java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.romi.parcelablecreatortest / com.example.romi.parcelablecreatortest.MainActivity}:android.view.InflateException:二进制XML文件行#1:二进制XML文件行#1 :错误膨胀类片段                                                                                               在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)                                                                                               在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                                               在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                               在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                               在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                               在android.os.Looper.loop(Looper.java:148)                                                                                               在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                                               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)                                                                                            引起:android.view.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误膨胀类片段                                                                                               在android.view.LayoutInflater.inflate(LayoutInflater.java:539)                                                                                               在android.view.LayoutInflater.inflate(LayoutInflater.java:423)                                                                                               在android.view.LayoutInflater.inflate(LayoutInflater.java:374)                                                                                               在android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)                                                                                               在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)                                                                                               在com.example.romi.parcelablecreatortest.MainActivity.onCreate(MainActivity.java:11)​​

以下是代码:

activity_main.xml中

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment"
    android:name="com.example.romi.parcelablecreatortest.MainActivityFragment"
    android:layout="@layout/activity_main_activity_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

MainActivity.java

package com.example.romi.parcelablecreatortest;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

1 个答案:

答案 0 :(得分:1)

您没有初始化TopRatedMovieJson[] topRatedMovieJson;这就是您{/ 1}}

的原因
NPE

java.lang.NullPointerException: storage == null at java.util.Arrays$ArrayList.(Arrays.java:38) at java.util.Arrays.asList(Arrays.java:155) at com.example.romi.parcelablecreatortest.MainActivityFragment.onCreate(MainActivityFragment.java:74)

中更新
MainActivityFragment's