-1

hello guys i have being trying make a user profile for weeks now, i want to add a button and text input layout so the users can edit there profile but every time i click on the save button the applications crash i used a method from simplified coding

public class ProfileActivity extends AppCompatActivity {

private static final int CHOOSE_IMAGE = 100;

ImageView buttonmessages;
ImageView selectimage;
ImageView share;
ImageView backgroundd;
ImageView notverified;
Button savebt;


private TextInputEditText profilename;
TextInputEditText email;
TextInputEditText phone;
TextInputEditText password;

Uri uriProfileImage;

String profileImageUrl;

FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    buttonmessages = findViewById(R.id.btmessages);
    backgroundd  = findViewById(R.id.upload2);
    share = findViewById(R.id.share);
    selectimage = findViewById(R.id.upload);
    notverified = findViewById(R.id.notverified);
    profilename= findViewById(R.id.um);
    email  =findViewById(R.id.proemail);
    phone = findViewById(R.id.prophone);
    password = findViewById(R.id.Propassword);
    savebt =findViewById(R.id.savebutton);



    buttonmessages.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(ProfileActivity.this,
                    ChatActivity.class);
            startActivity(myIntent);
        }
    });
    selectimage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showImageChooser();
        }
    });

    backgroundd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showImageChooser();
        }
    });

    findViewById(R.id.savebutton).setOnClickListener(new 
  View.OnClickListener() {
        @Override
        public void onClick(View view) {
            saveUserInformation();
        }
    });


}
private void saveUserInformation() {


    String displayName = profilename.getText().toString();

    if (displayName.isEmpty()) {
        profilename.setError("Name required");
        profilename.requestFocus();
        return;
    }

    FirebaseUser user = mAuth.getCurrentUser();

    if (user != null && profileImageUrl != null) {
        UserProfileChangeRequest profile = new 
  UserProfileChangeRequest.Builder()
                .setDisplayName(displayName)
                .setPhotoUri(Uri.parse(profileImageUrl))
                .build();

        user.updateProfile(profile)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            Toast.makeText(ProfileActivity.this, "Profile 
Updated", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
}

THIS IS THE ERROR I GOT

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.ayodkay.app.bookshare, PID: 18097
              java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.support.design.widget.TextInputEditText.getText()' on a null object reference
                  at com.ayodkay.app.bookshare.ProfileActivity.saveUserInformation(ProfileActivity.java:104)
                  at com.ayodkay.app.bookshare.ProfileActivity.access$100(ProfileActivity.java:29)
                  at com.ayodkay.app.bookshare.ProfileActivity$4.onClick(ProfileActivity.java:95)
                  at android.view.View.performClick(View.java:5052)
                  at android.view.View$PerformClick.run(View.java:20162)
                  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:5753)
                  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:1405)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

please if you know anything thing i can do to solve this i will be be very happy or if you have another method to this i will also appreciate it

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
Ayodele Kayode
  • 330
  • 3
  • 15

1 Answers1

0

profilename is null, check that you are inflating this view, probably you are refering an id that it is not in the layout you are inflating

cherif
  • 979
  • 1
  • 9
  • 15