创建个人资料活动

时间:2018-03-04 18:45:14

标签: android nullpointerexception

大家好我已经尝试了几个星期的用户档案,我想添加一个按钮和文本输入布局,以便用户可以编辑那里的配置文件,但每次我点击保存按钮应用程序崩溃我使用的方法来自简化编码

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();
                        }
                    }
                });
    }
}

这是我的错误

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)

如果您知道我可以做任何事情来解决这个问题,我将非常高兴,或者如果您有其他方法,我也会很感激

1 个答案:

答案 0 :(得分:0)

Type SIZE V1 V2 V1_lag V2_lag V1_lead V2_lead A 1 5 7 NA NA NA NA B 1 NA NA 5 7 2 4 B 3 NA NA 5 7 2 4 B 4 NA NA 5 7 2 4 A 8 2 4 NA NA NA NA A 6 6 50 NA NA NA NA A 12 2 8 NA NA NA NA B 8 NA NA 2 8 51 63 A 9 51 63 NA NA NA NA A 11 93 70 NA NA NA NA 为空,请检查您是否正在充气此视图,可能是您正在引用一个不在您正在膨胀的布局中的ID