-3
error image 这是错误信息片段必须是一个公共静态类从实例状态正确地重新创建
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hkmedical.hkmedical/com.hkmedical.hkmedical.pdf.DocumentActivity}: java.lang.IllegalStateException: Fragment com.hkmedical.hkmedical.pdf.DocumentActivity.PlaceholderFragment must be a public static class to be properly recreated from instance state.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
Caused by: java.lang.IllegalStateException: Fragment com.hkmedical.hkmedical.pdf.DocumentActivity.PlaceholderFragment must be a public static class to be properly recreated from instance state.
at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:384)
at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:369)
at com.hkmedical.hkmedical.pdf.DocumentActivity.onCreate(DocumentActivity.java:55)
at android.app.Activity.performCreate(Activity.java:6367)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
in the activity, when onCreate, the runtime exception appeared.
fragment = new PlaceholderFragment(this);
if (savedInstanceState == null) {
this.getSupportFragmentManager().beginTransaction()
.add(R.id.container, fragment).commit();
}
这里是哲内片段
@SuppressLint("ValidFragment")
public class PlaceholderFragment extends Fragment {
private Context mContext;
public PlaceholderFragment(Context context) {
mContext = context;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = new View(mContext);
rootView.setBackgroundColor(Color.GRAY);
mDoc = new SPDocument();
long lResult = mDoc.open(mFilePath);
if (lResult == 0) {
drawView();
}
return rootView;
}
public void drawView() {
mReaderView = new SPReaderViews(mContext, mDoc);
mView = mReaderView.showDocument();
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
getActivity().addContentView(mReaderView, params);
mView.goToPage(0);}
这是我的gradle产出:
compileSdkVersion 25
buildToolsVersion '25.0.0'
我想知道如何使它工作好,我想知道如何使我工作得很好,我想知道如何使它工作得很好。 但是zhe代码在我的其他项目中效果很好。
我想知道如何使它工作良好,我想知道如何使它工作得很好,我想知道如何使它工作良好。 但是zhe代码在我的其他项目中效果很好。
我想知道如何使它工作良好,我想知道如何使它工作得很好,我想知道如何使它工作良好。 但是zhe代码在我的其他项目中效果很好。
将“添加”更改为“替换” –
片段应该只有空构造函数。 –