Click here to Skip to main content
15,887,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My login app is not working on Android.Whenever I run the app on a mobile phone or AVD it says, unfortunately, the app has stopped.
The app is crashing

Where I went wrong?
can someone help me out?

What I have tried:

Java
MainActivity

   package com.example.nikhilarora.loginform;
   import android.content.Intent;
   import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.EditText;
            
   public class MainActivity extends AppCompatActivity implements View.OnClickListener {
        
      EditText editText, editText2;
      Button b;
        
      @Override
      protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         editText = (EditText) findViewById(R.id.editText);
         editText2 = (EditText) findViewById(R.id.editText2);
         b = findViewById(R.id.button);
         b.setOnClickListener(this);
      }
        
      @Override
      public void onClick(View v) {
         if (v.getId() == R.id.button) {
            if (editText.getText().toString().equals("admin") && editText.getText().toString().equals("admin")) {
               Intent i = new Intent(this, Main2Activity.class);
               startActivity(i);
            }
        }
     }
  }
        
  Xml file
  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout 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"
  tools:context="com.example.nikhilarora.loginform.MainActivity">
        
  <TextView
  android:id="@+id/textView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentStart="true"
  android:layout_below="@+id/imageView2"
  android:layout_marginLeft="14dp"
  android:layout_marginStart="14dp"
  android:layout_marginTop="15dp"
  android:textStyle="bold"
  android:text="UserName" />
        
  <EditText
  android:id="@+id/editText"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/textView"
  android:layout_alignStart="@+id/textView"
  android:layout_below="@+id/textView"
  android:hint="Name"
  android:ems="10"
  android:inputType="textPersonName"
  android:text="" />
        
  <ImageView
  android:id="@+id/imageView2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"
  android:maxWidth="80dp"
  android:maxHeight="100dp"
  android:scaleType="fitCenter"
  android:layout_marginLeft="125dp"
  app:srcCompat="@drawable/login" />
        
  <TextView
  android:id="@+id/textView2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignEnd="@+id/textView"
  android:layout_alignRight="@+id/textView"
  android:layout_below="@+id/editText"
  android:layout_marginTop="20dp"
  android:text="TextView" />
        
  <EditText
  android:id="@+id/editText2"
  android:layout_width="wrap_content"
  android:hint="password"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/textView2"
  android:layout_alignStart="@+id/textView2"
  android:layout_below="@+id/textView2"
  android:layout_marginTop="11dp"
  android:ems="10"
  android:inputType="textPassword"
  />
        
  <button
  android:id="@+id/button" 
="" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/imageView2" android:layout_alignstart="@+id/imageView2" android:layout_below="@+id/editText2" android:layout_margintop="27dp" android:text="Login">
Posted
Updated 13-Feb-18 13:39pm
v2
Comments
David Crow 13-Feb-18 20:47pm    
"Where I went wrong?"

By not single-stepping through the code using the debugger, and not having any error checking or try/catch blocks.
Arunprasath Natarajan 13-Feb-18 23:20pm    
"unfortunately, the app has stopped."
It means not only the error must be in your login process code.
It can be other also - So use try catch block and check it out.
Arunprasath Natarajan 13-Feb-18 23:22pm    
Share the code of landing page as well.
JoCodes 16-Feb-18 8:42am    
Can you share any logcat errors?
nikhil arora 24-Feb-18 9:03am    
thanks, buddies I have solved the error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900