Android SharedReference、facebook集成、NullPointerException

Android SharedReference、facebook集成、NullPointerException,android,android-fragments,android-sharedpreferences,Android,Android Fragments,Android Sharedpreferences,我正在尝试将facebook与我的应用程序集成。 我的登录按钮位于活动中的一个片段中 当我回到我的主要活动,回到我的facebook活动。 我得到空指针异常。 我使用共享首选项来保存用户的数据,并将其设置在特定的文本视图上 facebook登录的片段(为了提问,我删除了导入) 在设置setText之前,请确保未传递NULL值。我认为问题在于这里,传递的值必须为null,因此为NullPointerException email.setText(email1);

我正在尝试将facebook与我的应用程序集成。 我的登录按钮位于活动中的一个片段中

当我回到我的主要活动,回到我的facebook活动。 我得到空指针异常。 我使用共享首选项来保存用户的数据,并将其设置在特定的文本视图上

facebook登录的片段(为了提问,我删除了导入)


在设置setText之前,请确保未传递NULL值。我认为问题在于这里,传递的值必须为null,因此为NullPointerException

                email.setText(email1);
                gende.setText(gender1);
                birthday.setText(birthday1);
将您的
onResume()
更改为如下所示:

public void onResume() {
        super.onResume();
        textView = (TextView) getView().findViewById(R.id.textView);
        email = (TextView) getView().findViewById(R.id.emailid);
        gende = (TextView) getView().findViewById(R.id.gender);
        birthday = (TextView) getView().findViewById(R.id.birth);
        Profile profile = Profile.getCurrentProfile();
        displayMessage(profile);
        AppEventsLogger.activateApp(getContext());
    }

post the stacktrace Completely显示TextView引用为空或您传递的值为空。是的,它为空,但为什么,我试图将值保存在SharedReferences的变量中…@Xoce웃Пepeúpa-am上传完整日志。。我的情况是,当我第一次登录facebook时,我能够获取用户的所有详细信息,并能够在各种文本视图上进行设置。。但是一旦我回到我的主活动,然后又从主活动转到登录活动,它就会崩溃..我知道它传递的是null值,但我想知道我应该如何执行SharedReference的实现,这样我就不会在其中放入null值。在传递值之前,检查它是否包含null值。是的,我有:)但是其他一些方法
FATAL EXCEPTION: mainProcess: earn.free.cashback.snapcash, PID: 3959
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at earn.free.cashback.snapcash.fragments.Profilee.displayMessage(Profilee.java:241)
at earn.free.cashback.snapcash.fragments.Profilee.onResume(Profilee.java:268)
at earn.free.cashback.snapcash.fragments.Profilee.onCreate(Profilee.java:149)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:926)
at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:876)
at android.support.v4.app.FragmentPagerAdapter.setPrimaryItem(FragmentPagerAdapter.java:130)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1175)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:664)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:731)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
at android.view.View.measure(View.java:17430)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                email.setText(email1);
                gende.setText(gender1);
                birthday.setText(birthday1);
public void onResume() {
        super.onResume();
        textView = (TextView) getView().findViewById(R.id.textView);
        email = (TextView) getView().findViewById(R.id.emailid);
        gende = (TextView) getView().findViewById(R.id.gender);
        birthday = (TextView) getView().findViewById(R.id.birth);
        Profile profile = Profile.getCurrentProfile();
        displayMessage(profile);
        AppEventsLogger.activateApp(getContext());
    }