Reputation: 339
I have a ListFragment that is crashing when its called. I do not know how to fix this. I would appreciate a new pair of eyes. So lets get into it, here is my code and error log.
Fragment
public class Incidents_Frag extends ListFragment {
View view;
public static Model model;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.incid, container, false);
model = new Model();
setListAdapter(new ArrayAdapter<Incident>(getActivity(),
android.R.layout.simple_list_item_1, model.getIncidents()));
return view;
}
}
Fragment XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Logcat
04-21 23:54:30.615: E/AndroidRuntime(890): FATAL EXCEPTION: main
04-21 23:54:30.615: E/AndroidRuntime(890): java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.ListFragment.ensureList(ListFragment.java:402)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.ListFragment.onViewCreated(ListFragment.java:203)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:809)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.BackStackRecord.run(BackStackRecord.java:622)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1330)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:417)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.os.Handler.handleCallback(Handler.java:605)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.os.Handler.dispatchMessage(Handler.java:92)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.os.Looper.loop(Looper.java:137)
04-21 23:54:30.615: E/AndroidRuntime(890): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-21 23:54:30.615: E/AndroidRuntime(890): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 23:54:30.615: E/AndroidRuntime(890): at java.lang.reflect.Method.invoke(Method.java:511)
04-21 23:54:30.615: E/AndroidRuntime(890): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-21 23:54:30.615: E/AndroidRuntime(890): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-21 23:54:30.615: E/AndroidRuntime(890): at dalvik.system.NativeStart.main(Native Method)
As we can see from the error log I am apparently trying to inflate something that is not of the type "listview". I actually added the listview inside the fragment xml aftewards with an id of "list" just to see if it would work. It didn't. I think the key is in the 2nd line of the error log yet I don't know how to fix it.
Thank you for any help offered.
Upvotes: 0
Views: 250
Reputation: 30168
It seems like you're creating a new "list" id, but you should be using the one provided by android: android:id="@id/android:list"
Upvotes: 2