0
我有一個ListFragment在調用時會崩潰。我不知道如何解決這個問題。我會欣賞一雙新的眼睛。所以讓我們進入它,這裏是我的代碼和錯誤日誌。Android ListFragment運行時錯誤
片段
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;
}
}
片段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)
我們可以從ERR見或日誌我顯然試圖誇大一些不是「listview」類型的東西。我實際上在list xml後面添加了listview,並且只是爲了查看它是否可行。它沒有。我認爲關鍵是在錯誤日誌的第二行,但我不知道如何解決它。
謝謝你提供的任何幫助。
。現在它不顯示我的數組即時通過,但這是一個單獨的問題 – IrishWhiskey 2013-04-22 01:47:36
謝謝你,提出了我的問題! – 2013-09-24 21:08:56