Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

Android project gives InflateException error.

And this is the error from the Android Studio Android Monitor:

--------- beginning of crash 07-14 00:03:23.801 13726-13726/com.example.romi.parcelablecreatortest E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.romi.parcelablecreatortest, PID: 13726 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.romi.parcelablecreatortest/com.example.romi.parcelablecreatortest.MainActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.example.romi.parcelablecreatortest.MainActivity.onCreate(MainActivity.java:11)

Here is the code:

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);
    }
}
share|improve this question

you are not initialised TopRatedMovieJson[] topRatedMovieJson;that's why you got NPEat

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)

update in MainActivityFragment's

 public void jsonParser(String json) {

        final String LOG_TAG = MainActivityFragment.class.getSimpleName();

        // The variables that we want from the json file
        final String title = "original_title"; // JSONObject
        final String posterPath = "poster_path"; // JSONObject
        final String synopsis = "overview"; // JSONObject
        final String userRating = "popularity"; // JSONObject
        final String releaseDate = "release_date"; // JSONObject

        // Parsing the json file
        try {
            JSONArray jsonArray = new JSONArray(json);
            // for is used to cycle through the json array.
            topRatedMovieJson= new TopRatedMovieJson[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i); // getJSONObject(i) will take onw of the json array with i=0 as its first index
                topRatedMovieJson[i] = new TopRatedMovieJson(
                        jsonObject.getString(title),
                        jsonObject.getString(posterPath),
                        jsonObject.getString(synopsis),
                        jsonObject.getString(userRating),
                        jsonObject.getString(releaseDate)
                );
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
share|improve this answer
    
Thanks. I initialize it in onCreate. topRatedMovieJson = new TopRatedMovieJson[1000]; – QuartZ Jul 13 at 19:04
    
But it still doesn't solve the InflateException error. Any more solution to try? – QuartZ Jul 14 at 16:03
    
@QuartZ I don't have time for solve your full application's errors . first read full logcat and try to error by yourself . if you got error in other line then edit your question. – Mr X Jul 14 at 16:38
    
Please try cleaning your project and rebuild it! – Eenvincible Jul 14 at 17:46
    
Thanks. I fix it. The problem is in the xml. – QuartZ Jul 22 at 8:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.