尝试在空对象引用上调用虚拟方法 'void android.widget.EditText.setText(java.lang.CharSequence)'

Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference

我正在尝试设置从数据库中获取的 Edittext 小部件的文本(数据),但是我遇到了上述错误,我正在尝试解决但没有得到实际的想法,请帮助我解决这个问题,在此先感谢,

这是我的MainActivity.java

package com.mycompany.newlogin;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

Button btLogout;
EditText etName,etPhone,etEmail,etUsername;
private static String url = "jdbc:mysql://31.170.160.74:3306/a5582611_mane";
private static String user = "a5582611_nanu";
private static String password = "sonne0";
UserLocalStore userLocalStore;


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    etName=(EditText)findViewById(R.id.etName);
    etPhone=(EditText)findViewById(R.id.etPhone);
    etEmail=(EditText)findViewById(R.id.etEmail);
    etUsername=(EditText)findViewById(R.id.etUsername);
    btLogout=(Button)findViewById(R.id.btLogout);
    userLocalStore=new UserLocalStore(this);

    btLogout.setOnClickListener(this);

}
@Override
protected void onStart(){
    super.onStart();
    if(authenticate()==true){
        //go to your question window
        displayUserDetails();
    }else {
        startActivity(new Intent(MainActivity.this,Login.class));

    }
}
private void displayUserDetails(){
    User user=userLocalStore.getLoggedInUser();
    etName.setText(user.name);
    etEmail.setText(user.email);
    etUsername.setText(user.username);
}

private boolean authenticate(){
    return userLocalStore.getUserLoggedIn();
}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btLogout:
            userLocalStore.clearUserData();
            userLocalStore.setUserLoggedIn(false);
           startActivity(new Intent(this, Login.class));
            break;
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

而我的activity_xml文件是这样的,

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"/>
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etName"
    android:layout_marginBottom="10dp"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email"/>
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Email"
    android:layout_marginBottom="10dp"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Username"/>
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etUsername"
    android:layout_marginBottom="10dp"
    />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/btLogout"
    android:text="Logout"
    android:layout_gravity="center"/>

这是我的错误详情,

请帮我解决这个问题

您的 etEmail 编辑文本为空:

代替- etEmail=(EditText)findViewById(R.id.etEmail);

应该是-etEmail=(EditText)findViewById(R.id.Email);

因为您的 etEmail id 是 "Email" 而不是 "etEmail"。