0
02-13 05:29:12.454: E/AndroidRuntime(1374): FATAL EXCEPTION: main
02-13 05:29:12.454: E/AndroidRuntime(1374): Process: net.multiplesystem.nosms, PID: 1374
02-13 05:29:12.454: E/AndroidRuntime(1374): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.ListFragment.ensureList(ListFragment.java:344)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.View.measure(View.java:16458)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.View.measure(View.java:16458)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.View.measure(View.java:16458)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2289)
02-13 05:29:12.454: E/AndroidRuntime(1374):     at android.view.View.measure(View.java:16458)

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

JAVA

public class UserDetails extends ListFragment  {
    ArrayAdapter<String> adapter;
    ArrayList<String> userIndex = new ArrayList<String>();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View android = inflater.inflate(R.layout.users_tab, container, false);   
        adapter = new ArrayAdapter<String>(inflater.getContext(),R.layout.single_user_chat_tab,userIndex);
        setListAdapter(adapter);
        return android;
    }
}

When i execute the program it show the run time exception. But i all-ready have listview with id list. I have no idea why it shows the exception. please guide me friends why it throws the exception.I have tried all the solution but still get the same problem.

Android Learner
  • 319
  • 2
  • 5
  • 19

2 Answers2

1

I don't think you can call setListAdapter before returning your custom View in the onCreateView. I see 3 solutions

  1. Either call super.onCreateView() instead of inflating
  2. Either set your adapter in OnActivityCreated
  3. Either write android.findViewById(android.R.id.list).setAdapter(adapter); instead
Benoit
  • 1,922
  • 16
  • 25
0
 <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />  
Pararth
  • 8,114
  • 4
  • 34
  • 51
  • not working. My activity class extends ListFragment. – Android Learner Feb 13 '14 at 10:40
  • @AndroidLearner check now, Source: http://developer.android.com/reference/android/app/ListFragment.html – Pararth Feb 13 '14 at 10:44
  • 1
    When using ListActivity or ListFragment, we must have a ListView in our layout xml whose id is = @id/android:list. Since ListActivity and ListFragment internally use this id to create a list and this is the list which is referred or returned by getListView(). – Atul O Holic Feb 13 '14 at 10:48