In the LoginActivity class it doesnt show anything wrong but whenever i try to run the app and try to login by clicking on the Login button it fails and the logcat says ObjectOnNull reference. I cant login, also the emulator doesnt show the updated changes i made.
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.anisacoding.rappers.Fragments.Dashboard;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.Objects;
public class LoginActivity extends AppCompatActivity {
EditText Email, Password;
TextView text_register;
Button Login;
FirebaseAuth auth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
Email = findViewById(R.id.Email);
Password = findViewById(R.id.Password);
Login = findViewById(R.id.Login);
text_register = findViewById(R.id.text_register);
auth = FirebaseAuth.getInstance();
text_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view){
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
Login.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick (View view){
final Dialog pd = new Dialog( LoginActivity.this);
pd.setTitle("Please wait.....");
pd.show();
String str_Email = Email.getText().toString();
@NonNull
String str_Password = Password.getText().toString();
if (TextUtils.isEmpty(str_Email) || TextUtils.isEmpty(str_Password)) {
Toast.makeText(LoginActivity.this, "All fields are required, all texts", Toast.LENGTH_SHORT).show();
} else {
auth.signInWithEmailAndPassword(str_Email, str_Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Users").child(Objects.requireNonNull(auth.getCurrentUser()).getUid());
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
pd.dismiss();
Intent intent = new Intent(LoginActivity.this, Dashboard.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
pd.dismiss();
}
});
} else {
pd.dismiss();
Toast.makeText(LoginActivity.this, "Authentication failed", Toast.LENGTH_SHORT).show();
}
}
});
}
}
} );
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp"
tools:context=".LoginActivity">
<EditText
android:id="@+id/Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="9dp"
android:autofillHints=""
android:background="@drawable/edittext_background"
android:hint="@string/email_hin"
android:inputType="textEmailAddress"
android:padding="10dp"
android:text="@string/email_text"
app:layout_constraintBottom_toTopOf="@+id/Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.641" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="9dp"
android:autofillHints=""
android:background="@drawable/edittext_background"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:padding="10dp"
android:text="@string/password_text"
app:layout_constraintBottom_toTopOf="@+id/Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.795" />
<Button
android:id="@+id/Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="252dp"
android:background="@drawable/button_background"
android:text="@string/log_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.842"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/text_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="106dp"
android:textColor="@color/white"
android:layout_marginTop="37dp"
android:layout_marginEnd="95dp"
android:layout_marginBottom="196dp"
android:text="@string/register_question"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Logcat:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.anisacoding.rappers.LoginActivity$2.onClick(LoginActivity.java:68)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2020-09-05 17:02:13.661 3279-3399/com.google.android.googlequicksearchbox E/MDD: DownloadProgressMonitor: Can't find file group for uri: android://com.google.android.googlequicksearchbox/files/sharedminusonemodule/shared/SharedMinusOneData.pb.tmp
2020-09-05 17:02:14.915 1066-2168/com.google.android.apps.nexuslauncher E/ActivityThread: Failed to find provider info for com.google.android.apps.wellbeing.api
2020-09-05 17:02:41.700 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:02:41.700 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:02:47.997 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:02:47.997 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:03:06.393 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:03:07.265 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:03:07.452 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:03:33.037 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:03:33.244 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:03:41.773 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:03:41.779 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:03:48.017 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:03:48.017 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:04:41.814 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:04:41.815 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:04:48.047 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:04:48.047 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:04:57.706 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:04:57.863 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:04:57.934 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:05:10.578 508-572/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
2020-09-05 17:05:10.607 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:05:10.628 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:05:12.791 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:05:12.809 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:05:41.850 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:05:41.850 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:05:48.098 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:05:48.099 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:06:41.905 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:06:41.905 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:06:47.976 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:06:48.025 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:06:48.079 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:06:48.112 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:06:48.112 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:07:03.137 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:07:03.159 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:07:14.323 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:07:14.349 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:07:30.518 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:07:30.541 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:07:41.955 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:07:41.955 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:07:48.167 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:07:48.167 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:08:14.592 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:08:14.679 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:08:31.447 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:08:31.476 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:08:34.801 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:08:34.839 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:08:38.191 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:08:42.005 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:08:42.005 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:08:48.236 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:08:48.257 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:08:57.727 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:08:58.606 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:09:42.114 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:09:42.115 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:09:48.349 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:09:48.350 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:09:54.944 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:09:55.683 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:10:12.297 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:10:12.367 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:10:28.393 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:10:28.486 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:10:28.541 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:10:42.225 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:10:42.225 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:10:43.801 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:10:43.825 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:10:48.396 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:10:48.397 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:11:42.154 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:11:42.154 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:11:48.446 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2020-09-05 17:11:48.446 362-362/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2020-09-05 17:12:20.847 8137-10175/com.google.android.gms E/WakeLock: GCM_HB_ALARM release without a matched acquire!
2020-09-05 17:12:27.764 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:12:27.784 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:12:35.931 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied
2020-09-05 17:12:35.996 170-176/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup35: Permission denied
2020-09-05 17:12:42.204 399-399/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2020-09-05 17:12:42.204 399-399/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2020-09-05 17:12:48.498 362-362/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
How to solve this problem?