Question

I'm trying to write an application using the fragments with library ActionBarSherlock.

So, I have one problem.

My layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_FrameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        class="ru.neverdark.phototools.fragments.TitlesFragment"
        android:id="@+id/main_titlesFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

My MainActivity class:

package ru.neverdark.phototools;

import ru.neverdark.phototools.log.Log;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import android.os.Bundle;

public class MainActivity extends SherlockFragmentActivity {

    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.message("Enter");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

My TitlesFragment class:

package ru.neverdark.phototools.fragments;

import ru.neverdark.phototools.Constants;
import ru.neverdark.phototools.R;
import ru.neverdark.phototools.log.Log;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;

public class TitlesFragment extends SherlockListFragment {
    boolean mDualPane;
    int mCurrentCheckPosition = 0;
    final String[] TITLES = getResources().getStringArray(R.array.main_menuTitles);
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        Log.message("Enter");
        super.onActivityCreated(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(getActivity(),
                R.layout.menu_item,
                R.id.menuItem_label_title,
                TITLES));

        View detailsFrame = getActivity().findViewById(R.id.main_detailFragment);
        mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;

        if (savedInstanceState != null) {
            mCurrentCheckPosition = savedInstanceState.getInt(Constants.CURRENT_CHOICE, 0);
        }

        if (mDualPane) {
            getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            showDetails(mCurrentCheckPosition);
        }
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        outState.putInt(Constants.CURRENT_CHOICE, mCurrentCheckPosition);
    }

    @Override
    public void onListItemClick(ListView listView, View view, int position, long id) {
        showDetails(position);
    }

    private void showDetails(int index) {
        mCurrentCheckPosition = index;

        if (mDualPane == true) {
            getListView().setItemChecked(index, true);
            showFragment(index);
        } else {
            showActivity(index);
        }
    }

    private void showFragment(int index) {

    }

    private void showActivity(int index) {

    }
}

When I run the application, I get an exception

java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.neverdark.phototools/ru.neverdark.phototools.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

The exception occurs when setContentView function called.

Thanks in advance for any help.

Was it helpful?

Solution

Issue solved.

Problem string:

final String[] TITLES = getResources().getStringArray(R.array.main_menuTitles);

I change this for:

final String[] TITLES = {"test1", "test2"};//getResources().getStringArray(R.array.main_menuTitles);

And it working fine for me.

Tarun, thanks for helping in investigation problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top