0
我在片段中有一個imageView。在imageView上點擊我想開始一個活動。下面是我的代碼,顯示空指針異常。無法從片段中啓動活動
public static class DemoObjectFragment extends Fragment {
// public static final String ARG_OBJECT = "object";
Context con=getActivity();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_collection_object, container, false);
Bundle args = getArguments();
ImageView shadow_img=(ImageView) rootView.findViewById(R.id.shadow_img);
ImageView img=(ImageView)rootView.findViewById(R.id.img);
img.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(), Article.class);
getActivity().startActivity(intent);
}
});
shadow_img.setImageResource(R.drawable.featured_shadow);
new ImageLoadTask(args.getString("img_url"),(ImageView)rootView.findViewById(R.id.img),con).execute(null, null);
return rootView;
}
}