与上次onCreate、onCreateView中初始化Textview导致错误不同:
查阅资料发现,这次是因为构造函数有问题造成的,仔细检查代码发现确实是有个空的构造函数,删除后无报错。
最佳答案:You shouldn't really be overriding the constructor anyway. You should have a
newInstance()
static method defined and pass any parameters via arguments (bundle)
例如:
public static final AlertFragment newInstance(int title, String message){
AlertFragment f = new AlertFragment();
Bundle bdl = new Bundle(2);
bdl.putInt(EXTRA_TITLE, title);
bdl.putString(EXTRA_MESSAGE, message);
f.setArguments(bdl);
return f;}
运行日志报错内容;
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx.cscc/xxx.cscc.activity.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment xxx.cscc.fragment.cert.CerApplyingFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2406)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)