无法找到此 logcat 消息中的问题所在

Having trouble finding where the issue in this logcat message

我似乎无法在此 logcat 消息中找到崩溃的根源。我真的希望有人能帮忙。如果不是不用担心。这是应用程序崩溃前我收到的消息:(我真的很抱歉拖了这么久)

09-11 11:34:00.889 22547-22547/co.uk.mednet.mednet_ghana E/AndroidRuntime: FATAL EXCEPTION: main Process: co.uk.mednet.mednet_ghana, PID: 22547 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String co.uk.mednet.mednet_ghana.model.User.getTitle()' on a null object reference at co.uk.mednet.mednet_ghana.fragments.PatientInofrmationFragment.onCreateView(PatientInofrmationFragment.java:76) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149) at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103) at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984) at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) at android.support.v4.view.ViewPager.populate(ViewPager.java:1268) at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18926) at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435) at android.widget.LinearLayout.measureVertical(LinearLayout.java:721) at android.widget.LinearLayout.onMeasure(LinearLayout.java:612) at android.view.View.measure(View.java:18926) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5908) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3076) at android.view.View.measure(View.java:18926) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2411) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1429) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1677) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1314) at androi

OnCreateView 代码:

    //----------------find by view--------------
    mTextName = (TextView) view.findViewById(R.id.Patient_info_text_name_patient);
    mEditFirstname = (EditText) view.findViewById(R.id.Patient_info_editText_firstname);
    mEditLastname = (EditText) view.findViewById(R.id.Patient_info_editText_lastname);
    mTextEmail = (TextView) view.findViewById(R.id.Patient_info_text_email_patient);
    mEditEmail = (EditText) view.findViewById(R.id.Patient_info_editText_email);
    mTextPhone = (TextView) view.findViewById(R.id.Patient_info_text_phone_patient);
    mEditPhone = (EditText) view.findViewById(R.id.Patient_info_editText_phone);
    mTextNum = (TextView) view.findViewById(R.id.Patient_info_text_num_patient);
    mEditNum = (EditText) view.findViewById(R.id.Patient_info_editText_num);
    mTextHCP = (TextView) view.findViewById(R.id.Patient_info_text_hcp_patient);
    mEditHCP = (EditText) view.findViewById(R.id.Patient_info_editText_hcp);

    mEditFirstname.setVisibility(View.GONE);
    mEditLastname.setVisibility(View.GONE);
    mTextName.setText(PatientActivity.sPatient.getLastname()+" "+PatientActivity.sPatient.getFirstname());
    mEditEmail.setVisibility(View.GONE);
    mTextEmail.setText(PatientActivity.sPatient.getEmail());
    mEditPhone.setVisibility(View.GONE);
    mTextPhone.setText(Long.toString(PatientActivity.sPatient.getPhone_number()));
    mEditNum.setVisibility(View.GONE);
    mTextNum.setText(PatientActivity.sPatient.getPatient_number());
    mEditHCP.setVisibility(View.GONE);
    mTextHCP.setText(format("{0}. {1}", PatientActivity.sHCP.getTitle(), PatientActivity.sHCP.getLastname()));

    return view;
}

问题根源在这里:

Attempt to invoke virtual method 'java.lang.String co.uk.mednet.mednet_ghana.model.User.getTitle()' on a null object reference at co.uk.mednet.mednet_ghana.fragments.PatientInofrmationFragment.onCreateView(PatientInofrmationFragment.java:76) at

异常是 NullPointerException:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String co.uk.mednet.mednet_ghana.model.User.getTitle()' on a null object reference

您正在尝试对空实例调用 .getTitle() 方法。

此处抛出异常:

co.uk.mednet.mednet_ghana.fragments.PatientInofrmationFragment.onCreateView(PatientInofrmationFragment.java)

第 76 行

它是 NullPointerException 你可以在前 3 行阅读它 -

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String co.uk.mednet.mednet_ghana.model.User.getTitle()' on a null object reference at co.uk.mednet.mednet_ghana.fragments.PatientInofrmationFragment.onCreateView(PatientInofrmationFragment.java:76) at

当你在 PatientInofrmationFragment[=23= 中执行 User.getTitle() 时,清楚地说 NullPointerException ] 在其 onCreateView 方法中。

现在怎么变成null了?您可能没有创建 User class.

的对象

似乎在 PatientInofrmationFragment.onCreateView() 中 User 为空,因此 User.getTitle() 创建了一个异常。您可以在 onCreateView() 中初始化视图,并在 onActivityCreated() 中更新数据。

在您的崩溃中查看这一行。

co.uk.mednet.mednet_ghana.model.User.getTitle()' on a null object reference

我想你还没有初始化 User

检查您的初始化,或者如果您从服务器接收它,请务必检查 用户模型 是否 Not null