android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.smile.android.open.ui.fragment.LeftBehideListFragment: make sure class name exists, is public,online casinos and has an empty constructor that is public。
其错误翻译为:Fragment初始化异常。刚开始很纳闷,之前项目一直好好的怎么一锁屏就报错呢!后面看了下后面的解释:确保类名存在且是公共的,并且同时拥有一个公共的空构造方法,没办法,它提示啥咱就改呗!于是就将我这个Fragment类提供一个公共的空的构造函数!果不其然这次不报错了!
解决方法:
建议创建您自己的片段,然后进行您自己的实例化方法:
public class MyFragment extends Fragment {
public MyFragment() {
// empty constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// here you can load whatever layout you want for your fragment
View v = inflater.inflate(R.layout.your_fragment_layout, container, false);
// for example set the address as a textview text, or do whatever you want with it
TextView tv = (TextView) v.findViewById(R.id.tvAddress);
tv.setText(getArguments().getString("address"));
return v;
}
public static MyFragment newInstance(String address) {
MyFragment myFragment = new MyFragment();
Bundle args = new Bundle();
args.putString("address", address);
myFragment.setArguments(args);
return myFragment;
}
}
然后在 onItemClick() 方法内:
// new fragment handling
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, MyFragmet.newInstance(fragmentAddresses[position]);
transaction.commit();