我有一个看起来很疯狂的错误???
我正在从我的活动中开始一个片段。
在我调用 startActivityForResult 的片段中,试图从图库中获取图像。
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Image"), SELECT_IMAGE);
当我从画廊回来时,我的应用程序崩溃了。我跟踪了这个问题,我看到当我返回我的活动时,我看到onCreate()
我的片段再次启动。我不明白为什么我的片段被再次创建,而我的 web 服务对象被删除了。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: Bug mWebServicesManager.getEditingBlogItem() return null sometimes, only when i open first time get image from galerie
Log.i("EditImageSectionFragment","mWebServicesManager.getEditingBlogItem() ="+mWebServicesManager.getEditingBlogItem());
mSection = (ImagesSection) mWebServicesManager.getEditingBlogItem().getSections().get(mSectionPosition);
}
当我在 HTC 手机上运行测试时,一切正常,我没有遇到这个错误。但是当我在我的 Nexus S (android 4.1) 上运行该应用程序时,当我尝试获取图像时它总是崩溃。
我想知道为什么我的片段又被创建了?为什么我的 webServiceManager 对象被删除了?
日志猫:
10-02 12:34:32.609: E/AndroidRuntime(32344): FATAL EXCEPTION: main
10-02 12:34:32.609: E/AndroidRuntime(32344): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.overblog/com.overblog.activities.EditActivity}: java.lang.NullPointerException
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.os.Looper.loop(Looper.java:137)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-02 12:34:32.609: E/AndroidRuntime(32344): at java.lang.reflect.Method.invokeNative(Native Method)
10-02 12:34:32.609: E/AndroidRuntime(32344): at java.lang.reflect.Method.invoke(Method.java:511)
10-02 12:34:32.609: E/AndroidRuntime(32344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-02 12:34:32.609: E/AndroidRuntime(32344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-02 12:34:32.609: E/AndroidRuntime(32344): at dalvik.system.NativeStart.main(Native Method)
10-02 12:34:32.609: E/AndroidRuntime(32344): Caused by: java.lang.NullPointerException
10-02 12:34:32.609: E/AndroidRuntime(32344): at com.overblog.fragments.EditImageSectionFragment.onCreateView(EditImageSectionFragment.java:174)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.Activity.performStart(Activity.java:5018)
10-02 12:34:32.609: E/AndroidRuntime(32344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
10-02 12:34:32.609: E/AndroidRuntime(32344): ... 11 more