2

Error in Log: pastebin.com/YLvmkAd4

FragmentSettings.class:

package com.android.app;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FragmentSettings extends PreferenceFragment {

    [..]

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
            mListPreference = (ListPreference) getPreferenceManager().findPreference("preference_key");
    
            return inflater.inflate(R.layout.activity_main, container, false);
        }
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar_actionbar"
            layout="@layout/toolbar_default"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:clickable="true"
            android:layout_height="match_parent">
            <ListView
                android:id="@android:id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </ListView>
        </FrameLayout>
    </LinearLayout>
    <!-- android:layout_marginTop="?android:attr/actionBarSize"-->
    <com.android.app.ScrimInsetsFrameLayout
        android:id="@+id/scrimInsetsFrameLayout"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:layout_gravity="start"
        app:insetForeground="#4000"
        android:elevation="10dp">

        <fragment
            android:id="@+id/fragment_drawer"
            android:name="com.android.app.NavigationDrawerFragment"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout="@layout/fragment_navigation_drawer" />
    </com.android.app.ScrimInsetsFrameLayout>


</android.support.v4.widget.DrawerLayout>

Devices:

Oppo N1, Android 4.2.2
Samsung Galaxy Note 1, Android 5.1.1

I've spent now hours and hours for this error and couldn't find it. The clue is that exactly the same app is working perfectly on Android 5.1.1.

Additional:

MainActivity.java pastebin.com/a2NZLZFm

NavigationDrawerFragment.java pastebin.com/PqTMiPp3

fragment_navigation_drawer.xml pastebin.com/eVeAdv17

8
  • What version of Android did it crash on? Commented May 31, 2015 at 0:28
  • I've added my used devices. Sorry, forgot that. Commented May 31, 2015 at 0:31
  • Well, it looks like there is a problem with your fragment. Did you define an id of fragment_drawer somewhere else maybe? I don't think it would be the app:layout part... Commented May 31, 2015 at 0:35
  • Thanks ok. I added all occurrences of "fragment_drawer". Commented May 31, 2015 at 0:39
  • where is your navigation drawer layout Commented May 31, 2015 at 0:40

3 Answers 3

1
<fragment
     android:id="@+id/fragment_drawer"
     android:name="com.android.app.NavigationDrawerFragment"
     android:layout_width="@dimen/navigation_drawer_width"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"/>

use this rather, and inflate the layout in your onCreateView() android will take care of adding it ViewGroup/window etc etc

it is this line in your MainActivity

 // Set up the drawer.
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, 
             (DrawerLayout) findViewById(R.id.drawer), mToolbar);

remove it and the error will go. Now the next thing is you let the Activity handle the Drawerlayout himself. so transfer all drawer codes to your activity and forget the setup() method in your fragment

The reason is since you declared the fragment as embeded in the Activity, android initiates it for you, so you do not need to set it up

hope it works

Sign up to request clarification or add additional context in comments.

11 Comments

I'm new to android and not familiar to "inflate", but learning. :) So please go in detail.
sorry SIr, what i mean is just replace this fragment element in your xml by removing the app:layout you get me? you have already inflated it in your oncreatview of your navi fragment, go to the fragment you will in inflater.inflate so all you need to do is just copy this in replace of yours more on inflate @8m47x
Yeah that was the easiest part so far :D What needs to be changed here: View view = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);?
nothing needs to be changed sir, its good, maybe you might want to change the last parameter to true.. i guess your problems are gone or?@8m47x
Nope.. Nothing changed :/
|
0

Well you all helped me a lot, but I fixed it by myself ;)

I changed..

public class FragmentSettings extends PreferenceFragment {

    public ListPreference mListPreference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mListPreference = (ListPreference) getPreferenceManager().findPreference("preference_key");
        return inflater.inflate(R.layout.activity_main, container, false);
    }
}

To..

public class FragmentSettings extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }

}

And removed with this onCreateView and mListPreference :) Hope this help others ;)

Comments

0

Add this line into your styles.xml file.

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.