java.lang.InstantiationException:no empty constructor解决方法

来源:互联网 发布:知乎 旅游带什么 编辑:程序博客网 时间:2024/05/21 00:18

问题描述:定义一个MyFragment,明明有一个空的构造函数,却始终报java.lang.InstantiationException:no empty constructor错误

public class MyFragment extends Fragment {    public MyFragment() {    }    @Override    public View onCreateView(LayoutInflater inflater,                             ViewGroup container, Bundle savedInstanceState) {        View rootView = inflater.inflate(R.layout.new_reminder_fragment, container, false);        ...        return rootView;    }}
解决方法:
public static class MyFragment extends Fragment {    public MyFragment() {    }
将类改成静态的即可。

0 0
原创粉丝点击