以下是我public class AnalListFragment extends ListFragment
类
public void addFooterLoader() {
Parcelable state = getListView().onSaveInstanceState();
setListAdapter(null);
LayoutInflater factory = LayoutInflater.from(getActivity());
View loaderView = factory.inflate(R.layout.list_more_content_footer, null);
getListView().addFooterView(loaderView); // EXCEPTION HERE
setAdapterData();
getListView().onRestoreInstanceState(state);
}
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_width="48dp"
android:layout_height="48dp" />
</RelativeLayout>
因此,当我在我的4.1 Android设备上运行此代码时,它确实很好。但是当我在2.2设备上运行它时会引发异常:
12-09 15:57:07.861: E/AndroidRuntime(10621): FATAL EXCEPTION: main
12-09 15:57:07.861: E/AndroidRuntime(10621): java.lang.NullPointerException
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:778)
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.ListView.addFooterView(ListView.java:421)
12-09 15:57:07.861: E/AndroidRuntime(10621): at android.widget.ListView.addFooterView(ListView.java:436)
12-09 15:57:07.861: E/AndroidRuntime(10621): at com.example.analytics.AnalListFragment.addFooterLoader(AnalListFragment.java:150)
我不知道什么是错的以及为什么它在2.2设备上不起作用。