-1

I just can't seem to find the root of the crash in this logcat message. I really hope someone can help with it. If not no worries. Here is the message I'm getting right before the app crashes: (i'm really sorry for it being so long)

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 Code:

    //----------------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;
}
  • It's right at the beginning. In `PatientInofrmationFragment.onCreateView` you're calling `getTitle()` at line 76 on some User model but there seem to be no instance of User. – Jakub Synowiec Sep 11 '17 at 10:52

5 Answers5

0

Root of the problem here:

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

Jeka
  • 1,364
  • 17
  • 33
0

The exception is a 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

You are trying to call the .getTitle() method on a null instance.

The exception has been thrown here:

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

at line 76

Yusef Maali
  • 2,201
  • 2
  • 23
  • 29
0

Its a NullPointerException And you can read it in the first 3 lines -

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

Clearly says NullPointerException when you do User.getTitle() in your PatientInofrmationFragment in its onCreateView method.

Now how is it null? You might not have created an object of your User class.

Kapil G
  • 4,081
  • 2
  • 20
  • 32
0

it seems like in the PatientInofrmationFragment.onCreateView() the User is null, so User.getTitle() has create a exception. you can init the view in the onCreateView(), and update data in the onActivityCreated().

Cwen
  • 1
0

In your crash look at this line.

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

I think you have not initialized the User.

Check your initialization or if you're receiving it from server make sure to check the User model is Not null.

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66