0
我正在學習如何使用ListFragment使用getview時,當它運行下面的代碼的應用程序崩潰崩潰:應用listfragment
public class profileListFragment extends ListFragment {
String[] countries = new String[] {"USA", "China"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(),
android.R.layout.simple_list_item_1,countries);
setListAdapter(adapter);
View retView = super.onCreateView(inflater, container, savedInstanceState);
return retView;//super.onCreateView(inflater, container, savedInstanceState);
}
public void onListItemClick(ListView I, View v, int position, long id){
I.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
I.setSelector(android.R.color.holo_blue_light);
}
}
我知道這是因爲,當getListView()語句我刪除它,它不會崩潰...
任何幫助非常讚賞
I/ActivityManager(352): START {cmp=myapp.app/.loadProfile u=0} from pid 24295
E/AndroidRuntime(24295): java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp.app/myapp.app.loadProfile}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
E/AndroidRuntime(24295): at myapp.app.loadProfile.onCreate(loadProfile.java:12)
E/AndroidRuntime(24295): at myapp.app.profileListFragment.onCreateView(profileListFragment.java:19)
11-10 22:15:01.002: W/ActivityManager(352): Force finishing activity myapp.app/.loadProfile
發佈崩潰的logcat跟蹤。 – Squonk
hm ...我下載了catlog,但不知道如何獲得logcat ...另外,我應該提到我在平板電腦上運行它不在模擬器上,不知道是否重要... – evan54
您是否真的閱讀catlog的說明?或嘗試菜單選項?您可以將整個logcat輸出發送給您自己,然後在此處複製/粘貼(儘管請僅複製/粘貼與崩潰相關的部分)。或者,使用USB連接平板電腦並使用DDMS。 – Squonk