Bundle空对象是怎么回事
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
代码:
按钮响应事件:
findViewById(R.id.wwwwwwwwww_ID).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
caonima ccc = new fragment1();
Bundle bundle = new Bundle();
bundle.putString("anhao","www");
ccc.setArguments(bundle);
android.app.FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.main_ID,new caonima()).commit();
}
});
fragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag1,container,false);
TextView textView = (TextView) view.findViewById(R.id.frag1_text_ID);
String data = (String) getArguments().get("anhao");
textView.setText(data);
return view;
}