0
MainFragment類後:的NullPointerException甚至膨脹所述片段
public class FragmentMain extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
GridView gridview = (GridView)getActivity().findViewById(R.id.grid_view);
gridview.setAdapter(new ImageAdapter(getActivity(), thumbnails)); //gridview is null!!!
getActivity().setTitle(title);
return view;
}
}
fragment_main.xml佈局(gridview的甚至充氣後爲空)
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" >
</GridView>