Android app crashing instead of showing the Toast and throwing IllegalArgumentException - java

I made a simple app with a LoginActivity. It is crashing and throwing an IllegalArgumentException if the EditText(s) are empty. I use Firebase Authentication. I tried by using assert but still it did not work.
Dummy credentials to reproduce the issue:
Email: abc#abc.com
Password: 123456
StartActivity.java
import android.app.ProgressDialog;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import android.content.Intent;
import android.app.Activity;
import android.content.SharedPreferences;
import java.util.Objects;
public class StartActivity extends AppCompatActivity {
private static final String TAG = "EmailPassword";
private FirebaseAuth mAuth;
private LinearLayout linear1;
private TextInputLayout textinputlayout1;
private TextInputLayout textinputlayout2;
private TextInputEditText edittext1;
private TextInputEditText edittext2;
private Button button1;
private TextView textview1;
private Intent i =new Intent();
private SharedPreferences user;
private ProgressDialog prog;
private OnCompleteListener<AuthResult> _mAuth_sign_in_listener;
private void reload(){}
private void updateUI(FirebaseUser user){}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAuth = FirebaseAuth.getInstance();
setContentView(R.layout.activity_start);
LinearLayout _nav_view = (LinearLayout) findViewById(R.id._nav_view);
TextInputLayout textinputlayout1 = findViewById(R.id.textinputlayout1);
TextInputLayout textinputlayout2 = findViewById(R.id.textinputlayout2);
edittext1 = findViewById(R.id.edittext1);
edittext2 = findViewById(R.id.edittext2);
Button button1 = findViewById(R.id.button1);
TextView textview1 = findViewById(R.id.textview1);
SharedPreferences user = getSharedPreferences("user", Activity.MODE_PRIVATE);
Intent i= new Intent();
textview1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i.setClass(getApplicationContext(), ForgotPassword.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signIn();
}
});
}
#Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
i.setClass(getApplicationContext(), MainActivity.class);
startActivity(i);
}
}
private void signIn(){
Toast.makeText(StartActivity.this,"Button clicked",Toast.LENGTH_SHORT).show();
String email=Objects.requireNonNull(edittext1.getText()).toString();
String password= Objects.requireNonNull(edittext2.getText()).toString();
if(edittext1!=null && edittext2!=null){
final ProgressDialog prog= new ProgressDialog(StartActivity.this);prog.setMax(100);prog.setMessage("Logging in...");prog.setIndeterminate(true);prog.setCancelable(true);
prog.show();
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(StartActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
final boolean success= task.isSuccessful();
if(success){
i.setClass(getApplicationContext(),MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
prog.cancel();
}
else{
final String error=task.getException()!=null?task.getException().getMessage():"";
prog.cancel();
Toast.makeText(StartActivity.this,""+error,Toast.LENGTH_LONG).show();
}
}
});
}
else {
prog.cancel();
Toast.makeText(getApplicationContext(),"Email/Password cannot be empty!", Toast.LENGTH_SHORT).show();
}
}
public void onClick(View view) {
}
}
MainActivity.java
package com.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toolbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private Toolbar toolbar1;
private Button button2;
private LinearLayout linear2;
private Intent i=new Intent();
private FirebaseUser user;
private TextView textview5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAuth = FirebaseAuth.getInstance();
FirebaseUser user= mAuth.getCurrentUser();
setContentView(R.layout.activity_main);
Toolbar toolbar1=findViewById(R.id.toolbar1);
LinearLayout linear2=findViewById(R.id.linear2);
textview5=findViewById(R.id.textview5);
Button button2=findViewById(R.id.button2);
assert user != null;
textview5.setText(user.getEmail());
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
i.setClass(getApplicationContext(),StartActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
});
toolbar1.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
Screenshot of the crash

You are getting IllegalArgumentException because you let the user sign in with empty credentials. This is happening because you checking against nullity the EditText objects and not the actual values:
if(edittext1!=null && edittext2!=null) { ... }
Which is not correct. You should check if the values that are inserted by the user are different than the empty String. The following if statement should do the trick:
if(!email.isEmpty() && !password.isEmpty()) { ... }
It would be also better if you display a message to the user when the email or the password is empty.

Related

Firebase chat app not displaying messages like whatsapp does

I am trying to come up with a chat app using Firebase Recycler adapter. The problem is that the sender's and receiver's chats are not displayed as expected. All the chats are displayed on the right. Despite the text being "Morning", the text is displayed as "Hello".
Below is my code
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.firebase.ui.database.SnapshotParser;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
import ultramodern.activity.besha.Adapter.MessageAdapter;
import ultramodern.activity.besha.Model.Chat;
import ultramodern.activity.besha.Model.Users;
public class Complete_new_Group extends AppCompatActivity implements View.OnClickListener{
Button fab,paybtn, depobtn, borrowbtn, borrowicon, depoicon, payicon;
CircleImageView sendtextbutton;
EditText text_send;
RecyclerView chatrecyclerView;
MessageAdapter messageAdapter;
public static final int MESSAGE_RIGHT=0;
public static final int MESSAGE_LEFT=1;
//private String user_id;
#Override
protected void onCreate(Bundle savedInstanceState) { ;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete_new__group);
Toast.makeText(this, "This area is still under development", Toast.LENGTH_LONG).show();
fab = findViewById(R.id.fab_complete_group);
paybtn = findViewById(R.id.button6);
depobtn = findViewById(R.id.button5);
borrowbtn = findViewById(R.id.button3);
borrowicon = findViewById(R.id.button8);
depoicon = findViewById(R.id.button9);
payicon = findViewById(R.id.button10);
sendtextbutton = findViewById(R.id.sendtextButton);
text_send = findViewById(R.id.text_send);
chatrecyclerView = findViewById(R.id.chatrecycler);
chatrecyclerView.setLayoutManager(new LinearLayoutManager(this));
fab.setOnClickListener(this);
paybtn.setOnClickListener(this);
depobtn.setOnClickListener(this);
borrowbtn.setOnClickListener(this);
borrowicon.setOnClickListener(this);
depoicon.setOnClickListener(this);
payicon.setOnClickListener(this);
sendtextbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String message = text_send.getText().toString();
if (!message.equals("")){
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
String userId = getIntent().getStringExtra("userId");
sendmessage(message,userId,firebaseUser.getUid());
}
else {
Toast.makeText(Complete_new_Group.this, "You can't send an empty message", Toast.LENGTH_SHORT).show();
}
text_send.setText("");
}
});
final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final String user_id;
Intent intent = getIntent();
user_id = intent.getStringExtra("userId");
assert user_id != null;
// Log.d("TRACK",user_id);
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
Users users = snapshot.getValue(Users.class);
readMessage(firebaseUser.getUid(),user_id,users.getImageURL());
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public void onClick(View view) {
if (view==fab){
paybtn.setVisibility(View.VISIBLE);
depobtn.setVisibility(View.VISIBLE);
borrowbtn.setVisibility(View.VISIBLE);
borrowicon.setVisibility(View.VISIBLE);
depoicon.setVisibility(View.VISIBLE);
payicon.setVisibility(View.VISIBLE);
}
if (view==paybtn){
Intent intent = new Intent(getApplicationContext(),Group_pay.class);
startActivity(intent);
}
if (view==payicon){
Intent intent = new Intent(getApplicationContext(),Group_pay_icon_activity.class);
startActivity(intent);
}
if (view==depobtn){
Intent intent = new Intent(getApplicationContext(),Group_deposit_button_activity.class);
startActivity(intent);
}
if (view==depoicon){
Intent intent = new Intent(getApplicationContext(),Group_depo_icon_activity.class);
startActivity(intent);
}
if (view==borrowbtn){
Intent intent = new Intent(getApplicationContext(),Group_deposit_button_activity.class);
startActivity(intent);
}
if (view==borrowicon){
Intent intent = new Intent(getApplicationContext(),Group_borrow_icon_activity.class);
startActivity(intent);
}
if (view==sendtextbutton){
}
}
private void sendmessage(String message,String sender, String reciever){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
HashMap<String,Object> hashMap = new HashMap<>();
hashMap.put("sender",sender);
hashMap.put("reciever",reciever);
hashMap.put("message",message);
reference.child("Chats").push().setValue(hashMap);
}
private void readMessage(final String myId, final String userId, String imageURL){
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Chats");
FirebaseRecyclerOptions<Chat> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<Chat>().setQuery(databaseReference, new SnapshotParser<Chat>() {
#NonNull
#Override
public Chat parseSnapshot(#NonNull DataSnapshot snapshot) {
String message = String.valueOf(snapshot.child("message").getValue());
String sender = String.valueOf(snapshot.child("sender").getValue());
String receiver = String.valueOf(snapshot.child("reciever").getValue());
return new Chat(message,sender,receiver);
}
}).build();
final FirebaseRecyclerAdapter<Chat,ViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Chat,ViewHolder>(firebaseRecyclerOptions) {
#Override
protected void onBindViewHolder(#NonNull final ViewHolder viewHolder, int i, #NonNull Chat chat) {
if (chat.getReceiver().equals(userId) && chat.getSender().equals(myId) || chat.getReceiver()
.equals(myId) && chat.getSender().equals(userId)){
viewHolder.showMessage.setText(chat.getMessage());
}
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
if (viewType == MESSAGE_RIGHT){
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_right,parent,false);
return new ViewHolder(view);
}
else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_left,parent,false);
return new ViewHolder(view);
}
}
#Override
public int getItemViewType(int position) {
Chat chat = getItem(position);
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (chat.getSender().equals(firebaseUser.getUid())){
return MESSAGE_LEFT;
}
else {
return MESSAGE_RIGHT;
}
//return super.getItemViewType(position);
}
};
chatrecyclerView.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView showMessage;
public ImageView profilepic;
public ViewHolder(#NonNull View itemView) {
super(itemView);
showMessage=itemView.findViewById(R.id.showMessage);
profilepic=itemView.findViewById(R.id.profilepic);
}
public void setText(String paramString){
this.showMessage.setText(paramString);
}
}
}
This is the output on both the sender and the receiver
I need some assistance

An intent redirects me to a wrong activity

Unfortunately the button I tried to design doesn't work. I have three activities: Login, Register and MainActivity (which is a blank activity) and on the Login activity I have this register button ("button") that I want to redirect to Register activity but it redirects me to a blank page when I run the app. What should I do?
package com.example.scooterzapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
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.ProgressBar;
import android.widget.Toast;
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;
public class Register extends AppCompatActivity {
FirebaseAuth fAuth;
EditText etEmail,etParola,etNume,etPrenume,etUsername,etVarsta,etNumarDeTelefon;
Button bReg;
ProgressBar progressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
etNume = findViewById(R.id.etNume);
etPrenume = findViewById(R.id.etPrenume);
etUsername = findViewById(R.id.etUsername);
etParola = findViewById(R.id.etParola);
etEmail = findViewById(R.id.etEmail);
etNumarDeTelefon = findViewById(R.id.etNumarDeTelefon);
etVarsta = findViewById(R.id.etVarsta);
bReg= findViewById(R.id.bReg);
fAuth=FirebaseAuth.getInstance();
progressBar=findViewById(R.id.progressBar);
if(fAuth.getCurrentUser()!= null){
startActivity(new Intent(getApplicationContext(),MainActivity.class));
finish();
}
bReg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String Email = etEmail.getText().toString().trim();
String Parola = etParola.getText().toString().trim();
if (TextUtils.isEmpty(Email)) {
etEmail.setError("Campul trebuie completat.");
return;
}
if (TextUtils.isEmpty(Parola)) {
etParola.setError("Campul trebuie completat.");
return;
}
if (Parola.length() < 6) {
etParola.setError("Parola trebuie sa fie formata din cel putin 6 caractere");
return;
}
progressBar.setVisibility(View.VISIBLE);
fAuth.createUserWithEmailAndPassword(Email,Parola).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
Toast.makeText(Register.this, "V-ati inregistrat cu succes!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),Login.class));
}else{
Toast.makeText(Register.this, "Inregistrare esuata.", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
Greet from Nice ;) try below code
button.setOnClickListener (new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,Register.class));
}
});

The password is invalid or the user does not have a password

I'm trying to create a login and register system in Android Studio using Firebase. Registration works pretty well, user is created in Firebase successfully. But whenever I try to login it gives me this error "The password is invalid or the user does not have a password" even though the password I entered is the same I registered with. I think the problem might be with my code because user can login perfectly when I create account for given user on Firebase Console directly. What might cause this problem?
I provided my login and my register activity code:
Login activity
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
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.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class MainActivity extends AppCompatActivity
{
private EditText emailLoginEditText, passwordLoginEditText;
private Button loginBtn;
private TextView signupLink, forgetPassword;
private ProgressDialog progressDialog;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailLoginEditText = findViewById(R.id.email_login);
passwordLoginEditText = findViewById(R.id.password_login);
loginBtn = findViewById(R.id.btn_login);
signupLink = findViewById(R.id.signup_reg);
forgetPassword = findViewById(R.id.forget_password);
progressDialog = new ProgressDialog(this);
mAuth = FirebaseAuth.getInstance();
signupLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
startActivity(new Intent(MainActivity.this, RegistrationActivity.class));
}
});
forgetPassword.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
startActivity(new Intent(MainActivity.this, ResetActivity.class));
}
});
loginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
loginDetails();
}
});
}
private void loginDetails()
{
String email = emailLoginEditText.getText().toString().trim();
String password = passwordLoginEditText.getText().toString();
if(TextUtils.isEmpty(email))
{
emailLoginEditText.setError("Email can't be empty...");
return;
}
if(TextUtils.isEmpty(password))
{
passwordLoginEditText.setError("Password can't be empty...");
return;
}
else
{
progressDialog.setTitle("Login");
progressDialog.setMessage("Please wait while we are connecting you");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
else
{
progressDialog.dismiss();
Toast.makeText(MainActivity.this, "Error: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
}
}
And this is RegistrationActivity:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
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.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class RegistrationActivity extends AppCompatActivity
{
private EditText mEmailEditText, mPasswordEditText;
private Button mRegisterBtn;
private TextView SigninLink;
private ProgressDialog progressDialog;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
mEmailEditText = findViewById(R.id.email_reg);
mPasswordEditText = findViewById(R.id.password_reg);
mRegisterBtn = findViewById(R.id.btn_reg);
SigninLink = findViewById(R.id.signin_here);
progressDialog = new ProgressDialog(this);
mAuth = FirebaseAuth.getInstance();
SigninLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
startActivity(new Intent(RegistrationActivity.this, MainActivity.class));
}
});
registration();
}
private void registration()
{
mRegisterBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
String email = mEmailEditText.getText().toString().trim();
String password = mEmailEditText.getText().toString();
if(TextUtils.isEmpty(email))
{
mEmailEditText.setError("Email can't be empty...");
return;
}
if(TextUtils.isEmpty(password))
{
mPasswordEditText.setError("Password can't be empty...");
return;
}
progressDialog.setTitle("Creating Account");
progressDialog.setMessage("Please wait while we are creating your account");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
progressDialog.dismiss();
startActivity(new Intent(RegistrationActivity.this, HomeActivity.class));
}
else
{
Toast.makeText(RegistrationActivity.this, "Registration failed...", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
}
});
}
});
}
}

TAG And UpdateUI has private access in FragmentActivity Error For LoginActivity.java

Don't know why I am getting this error can anyone tell me that how to fix it.
this is login activity in java connected with firebase auth I am stuck in this before 3 days and still.
I pasted my code and also uploded my screen shot where you can see all the error.
Error where I always get on TAG and updateUI there two words always get error.
Download screen short of error message and code with error:
package com.eassycars.www.licencespot;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
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.auth.FirebaseUser;
public class Activity_Login extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
private Button singups,forgotpass,logins;
RelativeLayout really1, really2;
Handler handler = new Handler();
Runnable runnable = new Runnable() {
#Override
public void run() {
really1.setVisibility(View.VISIBLE);
really2.setVisibility(View.VISIBLE);
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
startActivity(new Intent(Activity_Login.this, MainActivity.class));
finish();
}
// set the view now
setContentView(R.layout.activity__login);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
singups = (Button) findViewById(R.id.singup);
logins = (Button) findViewById(R.id.logins);
forgotpass = (Button) findViewById(R.id.forgotpass);
singups.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, singup.class));
}
});
forgotpass.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, ForgotPassword.class));
}
});
really1 = (RelativeLayout) findViewById(R.id.rellayl);
really2 = (RelativeLayout) findViewById(R.id.really2);
handler.postDelayed(runnable, 2000);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
logins.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(Activity_Login.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
}
});
}
});
}
}
Can anyone help fix this error because I am beginner and I don't have much knowledge so I am trying to get it.
You are getting the error because you are missing TAG and UpdateUI method in the class :
Please add the following private static final String TAG = Activity_Login.class.getName(); as mentioned in the comment
Also, use the following method as you are using Firebase Auth
private void updateUI(FirebaseUser user) {
hideProgressDialog();
if (user != null) {
mStatusTextView.setText(getString(R.string.google_status_fmt, user.getEmail()));
mDetailTextView.setText(getString(R.string.firebase_status_fmt, user.getUid()));
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText(R.string.signed_out);
mDetailTextView.setText(null);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
}
After this you are good to go
You have to add TAG variable and updateUI method:
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
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.auth.FirebaseUser;
public class Activity_Login extends AppCompatActivity {
private static final String TAG = "Activity_Login";
private EditText inputEmail, inputPassword;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
private Button singups,forgotpass,logins;
RelativeLayout really1, really2;
Handler handler = new Handler();
Runnable runnable = new Runnable() {
#Override
public void run() {
really1.setVisibility(View.VISIBLE);
really2.setVisibility(View.VISIBLE);
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
startActivity(new Intent(Activity_Login.this, MainActivity.class));
finish();
}
// set the view now
setContentView(R.layout.activity__login);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
singups = (Button) findViewById(R.id.singup);
logins = (Button) findViewById(R.id.logins);
forgotpass = (Button) findViewById(R.id.forgotpass);
singups.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, singup.class));
}
});
forgotpass.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Activity_Login.this, ForgotPassword.class));
}
});
really1 = (RelativeLayout) findViewById(R.id.rellayl);
really2 = (RelativeLayout) findViewById(R.id.really2);
handler.postDelayed(runnable, 2000);
//Get Firebase auth instance
mAuth = FirebaseAuth.getInstance();
logins.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(Activity_Login.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
}
});
}
});
}
private void updateUI(FirebaseUser user) {
//implement your logic here
}
}

Getting "java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()" in Firebase

Image of DB in firebase console
I don't really know what's wrong here, I am able to add data on the other activity. I am getting error "java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()" and don't know how to fix. There are 3 other classes created only one other is adding data to firebase realtime database storage.
package com.example.akshay.katiroll.FirstScreen;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.akshay.katiroll.R;
import com.example.akshay.katiroll.SecondScreen.welcome;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Profile extends AppCompatActivity {
EditText fName, lName, PhNo, BDay, Zip;
Button svBtn;
DatabaseReference mDataReference;
String keyUser;
String fNameStr, lNameStr, PhNoStr, BDayStr, ZipStr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
keyUser = getIntent().getStringExtra("USER_KEY");
mDataReference = FirebaseDatabase.getInstance().getReference().child("Users").child(keyUser);//error in this line
fName = (EditText) findViewById(R.id.fName);
lName = (EditText) findViewById(R.id.lName);
PhNo = (EditText) findViewById(R.id.phno);
BDay = (EditText) findViewById(R.id.bday);
Zip = (EditText) findViewById(R.id.zip);
svBtn = (Button) findViewById(R.id.svBtn);
svBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fNameStr = fName.getText().toString();
lNameStr = lName.getText().toString();
PhNoStr = PhNo.getText().toString();
BDayStr = BDay.getText().toString();
ZipStr = Zip.getText().toString();
if(!TextUtils.isEmpty(fNameStr) && !TextUtils.isEmpty(lNameStr) && !TextUtils.isEmpty(PhNoStr)) {
DatabaseReference mDataRef = mDataReference.child("Users").push();
mDataRef.child("firstName").setValue(""+fNameStr);
mDataRef.child("lastName").setValue(""+lNameStr);
mDataRef.child("phoneNumber").setValue(""+PhNoStr);
mDataRef.child("isVerified").setValue("verified");
if(!TextUtils.isEmpty(BDayStr)){
mDataRef.child("birthday").setValue(""+BDayStr);
}else{
mDataRef.child("birthday").setValue("null");
}
if(!TextUtils.isEmpty(ZipStr)){
mDataRef.child("zipcode").setValue("ZipStr");
}else{
mDataRef.child("zipcode").setValue("null");
}
Toast.makeText(Profile.this, "User profile added", Toast.LENGTH_LONG).show();
startActivity(new Intent(Profile.this, welcome.class));
}else{
Toast.makeText(Profile.this, "Failed to create User Account", Toast.LENGTH_LONG).show();
}
}
});
}
}
package com.example.akshay.katiroll.FirstScreen;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.akshay.katiroll.R;
import com.example.akshay.katiroll.SecondScreen.welcome;
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.auth.FirebaseUser;
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.Iterator;
public class katiRoll extends AppCompatActivity {
EditText userEdit;
EditText passEdit;
String sUser, sPass;
Button sign;
Button reg;
Boolean signInVLogIn;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
DatabaseReference mDatabaseRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kati_roll);
float Re = 255;
float Gr = 148;
float Bl = 0;
userEdit = (EditText)findViewById(R.id.user);
passEdit = (EditText)findViewById(R.id.pass);
sign = (Button) findViewById(R.id.sign);
reg = (Button) findViewById(R.id.reg);
userEdit.setTextColor(Color.rgb(Re,Gr,Bl));
passEdit.setTextColor(Color.rgb(Re,Gr,Bl));
sign.setTextColor(Color.rgb(Re,Gr,Bl));
reg.setTextColor(Color.rgb(Re,Gr,Bl));
mAuth = FirebaseAuth.getInstance();
mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("Users");
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(!TextUtils.isEmpty(sUser) && !TextUtils.isEmpty(sPass)){
signInVLogIn = true;
}else{
signInVLogIn = false;
}
if(user != null && signInVLogIn) {
}else{
//Toast.makeText(katiRoll.this, "Log In Failed", Toast.LENGTH_LONG).show();
}
}
};
sign.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sUser = userEdit.getText().toString().trim();
sPass = passEdit.getText().toString().trim();
if(!TextUtils.isEmpty(sUser) && !TextUtils.isEmpty(sPass))
{
mAuth.signInWithEmailAndPassword(sUser, sPass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
mDatabaseRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
checkUserValidation(dataSnapshot, sUser);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}else{
Toast.makeText(katiRoll.this, "User Login Doesn't Exist" , Toast.LENGTH_LONG).show();
}
}
});
}
}
});
reg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(katiRoll.this, signUp.class));
}
});
}
private void checkUserValidation(DataSnapshot dataSnapshot, String emailForVer) {
Iterator iterator = dataSnapshot.getChildren().iterator();
while (iterator.hasNext())
{
DataSnapshot dataUser = (DataSnapshot)iterator.next();
if (dataUser.child("emailUser").getValue().toString().equals(emailForVer)){
if(dataUser.child("isVerified").getValue().toString().equals("unverified"))
{
Intent in = new Intent(katiRoll.this, Profile.class);
in.putExtra("USER KEY", dataUser.child("userKey").getValue().toString());
startActivity(in);
Log.d("USERKEY",dataUser.child("userKey").getValue().toString());
}
else{
startActivity(new Intent(katiRoll.this, welcome.class));
}
}
}
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
protected void onStop() {
super.onStop();
if(mAuthListener !=null){
mAuth.removeAuthStateListener(mAuthListener);
}
}
}
package com.example.akshay.katiroll.FirstScreen;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import com.example.akshay.katiroll.SecondScreen.welcome;
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.auth.FirebaseUser;
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.example.akshay.katiroll.R;
import com.google.firebase.database.ValueEventListener;
import java.util.Iterator;
public class signUp extends AppCompatActivity {
EditText nUser, nPass;
Button registerBtn, backToMain;
ImageButton passVis;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
DatabaseReference mDatabaseRef, mUserCheckData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
nUser = (EditText) findViewById(R.id.nUser);
nPass = (EditText) findViewById(R.id.nPass);
registerBtn = (Button) findViewById(R.id.registerBtn);
backToMain = (Button) findViewById(R.id.backToMain);
passVis = (ImageButton)findViewById(R.id.passVis);
passVis.setImageResource(R.drawable.open);
passVis.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Drawable drawable = passVis.getDrawable();
if(drawable.getConstantState().equals(getResources().getDrawable(R.drawable.open,null).getConstantState())){
passVis.setImageResource(R.drawable.closed);
nPass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}else{
passVis.setImageResource(R.drawable.open);
nPass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD);
}
}
});
float Re = 255;
float Gr = 148;
float Bl = 0;
nUser.setTextColor(Color.rgb(Re, Gr, Bl));
nPass.setTextColor(Color.rgb(Re, Gr, Bl));
registerBtn.setTextColor(Color.rgb(Re, Gr, Bl));
backToMain.setTextColor(Color.rgb(Re, Gr, Bl));
mAuth = FirebaseAuth.getInstance();
mDatabaseRef = FirebaseDatabase.getInstance().getReference();
mUserCheckData = FirebaseDatabase.getInstance().getReference().child("User");
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
final String emailForVer = user.getEmail();
mUserCheckData.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
checkForValidation(dataSnapshot, emailForVer);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Log.d("TAG", "onAuthStateChanged:signed_out");
}
}
};
registerBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String nUserString, nPassString;
nUserString = (nUser.getText().toString().trim());
nPassString = (nPass.getText().toString().trim());
if(nPassString.length()>=6){
if (!TextUtils.isEmpty(nUserString) && !TextUtils.isEmpty(nPassString)) {
mAuth.createUserWithEmailAndPassword(nUserString, nPassString).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
DatabaseReference mChildDatabase = mDatabaseRef.child("Users").push();
String key_user = mChildDatabase.getKey();
mChildDatabase.child("isVerified").setValue("unverified");
mChildDatabase.child("userKey").setValue(key_user);
mChildDatabase.child("EmailUser").setValue(nUserString);
mChildDatabase.child("PasswordUser").setValue(nPassString);
Toast.makeText(signUp.this, "User Account Created, Check Email For Confirmation", Toast.LENGTH_LONG).show();
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
user.sendEmailVerification();
}
startActivity(new Intent(signUp.this, Profile.class));
} else {
Toast.makeText(signUp.this, "Failed to create User Account", Toast.LENGTH_LONG).show();
}
}
});
} else {
Toast.makeText(signUp.this, "Failed to create User Account", Toast.LENGTH_LONG).show();
}
}else {
Toast.makeText(signUp.this, "Failed to create User Account", Toast.LENGTH_LONG).show();
}
}
});
backToMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(signUp.this, katiRoll.class));
}
});
}
private void checkForValidation(DataSnapshot dataSnapshot, String emailForVer) {
Iterator iterator = dataSnapshot.getChildren().iterator();
while (iterator.hasNext())
{
DataSnapshot dataUser = (DataSnapshot)iterator.next();
if (dataUser.child("emailUser").getValue().toString().equals(emailForVer)){
if(dataUser.child("isVerified").getValue().toString().equals("unverified"))
{
Intent in = new Intent(signUp.this, Profile.class);
in.putExtra("USER KEY", dataUser.child("userKey").getValue().toString());
startActivity(in);
Log.d("USERKEY",dataUser.child("userKey").getValue().toString());
}
else{
startActivity(new Intent(signUp.this, welcome.class));
}
}
}
}
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
protected void onStop() {
super.onStop();
if(mAuthListener !=null){
mAuth.removeAuthStateListener(mAuthListener);
}
}
}
package com.example.akshay.katiroll.SecondScreen;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.example.akshay.katiroll.FirstScreen.katiRoll;
import com.example.akshay.katiroll.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class welcome extends AppCompatActivity {
Button logOutBtn;
FirebaseAuth mAuth;
FirebaseAuth.AuthStateListener mAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
float Re = 255;
float Gr = 148;
float Bl = 0;
logOutBtn = (Button)findViewById(R.id.logOutBtn);
logOutBtn.setTextColor(Color.rgb(Re,Gr,Bl));
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user !=null) {
}else{
}
}
};
logOutBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mAuth.signOut();
finish();
startActivity(new Intent(welcome.this, katiRoll.class));
}
});
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(mAuthListener);
}
}
The problem that is telling to you is that you are doing wrong the reference, you are trying to get something inside Firebase Database that is not there
This line is telling you that the child("Users").child(KeyUser); does not exist in your current DB structure
To fix this you should see your databse structure and then redo your reference.
if you post a photo of your Firebase DB i will be glad to refactor your code to your needs.
also here you are getting wrong your USER_KEY
keyUser = getIntent().getStringExtra("USER_KEY");
To fix this a short way would be doing this
keyUser = getIntent().getExtras().getString("USER_KEY");
you are geting an intent from where? if you are trying to get a putExtra from another Activity, you are doing it wrong, post where you are seting the extra ("USER_KEY");
Intent.getStringExtra() and Intent.getExtras() returns null if there are no extras, so you need to check for that before trying to call getString()
one quick example to check for extras first would be this
String keyUser;
Bundle extras = getIntent().getExtras();
if(extras == null) {
Log.e("keyUser is null","");
} else {
keyUser= extras.getString("USER_KEY");
}
happy coding

Categories