I am creating a login screen for my application with more than 1 authentication. Now when i login the app with the first name and password, then it works but when i try the other names and password then it force closes the application.
I am using If and Else for the login Screen.
if (uName.equals("A") && uPass.equals("123"))
{
Intent cardSummaryScreen = new Intent(LoginActivity.this, Hi.class);
b = new Bundle();
EditText text1 = (EditText)findViewById(R.id.inputUserName);
b.putString("name", text1.getText().toString());
hi.putExtras(b);
startActivity(hi);
}
else if(uName.equals("sumit") && uPass.equals("456"))
{
Intent cardSummaryScreen1 = new
Intent(LoginActivity.this,Hi.class);
Bundle c= new Bundle();
EditText text2= (EditText)findViewById(R.id.inputUserName);
c.putString("name",text2.getText().toString());
startActivity(cardSummaryScreen1);
Even though you didn’t post a stacktrace, I think I can see where your app gets the error and force closes.
In your second
IF/ELSEstatement, you try to add extra data to your newhi1intent.However, you’re trying to add
b. This does not exist in your second statement, only in the first.Therefore your app is trying to add data that doesn’t exist, giving it a
NullPointerExceptionand force closing.