title: Getting error while calling Intent from fragment (User Login)
body: <p>I have getting error while calling intent from Fragment.
  Following are the log error of the same. Below are the pieces of code from the same activities. The application automatically gets off as i click on the Button for Login. 
  Please help me out. 
  Thank you in advance.</p>
  
  <p><strong>Log Report</strong> </p>
  
  <pre><code>Process: com.example.lenovo.skanda, PID: 7978
      java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
          at com.example.lenovo.skanda.AdminFragment$1.onClick(AdminFragment.java:43)
  </code></pre>
  
  <p><strong>HomeFragment.java</strong></p>
  
  <pre><code>  public class AdminFragment extends Fragment implements View.OnClickListener{
  
      View viewroot;
      View v1;
      private EditText Name;
      private EditText Password;
      static Button Login;
      public static Button myLog;
      private int Counter = 5;
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          viewroot = inflater.inflate(R.layout.fragment_admin,container,false);
  
          Name = (EditText) getActivity().findViewById(R.id.editText);
          Password = (EditText) getActivity().findViewById(R.id.editText2);
          Login = (Button) getActivity().findViewById(R.id.button2);
          myLog = (Button) viewroot.findViewById(R.id.button2);
          myLog.setOnClickListener(this);
  
  
          myLog.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v)
              {
                  validate(Name.getText().toString(), Password.getText().toString());
              }
          });
          return viewroot;
      }
  
  
  
      private void validate (String userName, String userPassword){
          if((userName.equals("Admin")) &amp;&amp;  (userPassword.equals("123"))){
              Intent intent = new Intent(AdminFragment.this.getActivity(), Login.class);
              startActivity(intent); //Login is the second activity
          }
          else {
  
              Counter --;
              Toast.makeText(getActivity(), "No. of Attempts Left for Login" + String.valueOf(Counter), Toast.LENGTH_SHORT).show();
  
              if (Counter == 0){
                  Login.setEnabled(false);
                  Toast.makeText(getActivity(), "For Enable the Login Please Contact..!!", Toast.LENGTH_SHORT).show();
  
              }
          }
      }
  
      @Override
      public void onClick(View v) {
          validate(Name.getText().toString(),Password.getText().toString());
      }
  }
  </code></pre>
  
  <p><strong>fragment_admin.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:background="@android:color/background_dark"&gt;
  
      &lt;com.airbnb.lottie.LottieAnimationView
          android:id="@+id/animation_view"
          android:layout_width="185dp"
          android:layout_height="155dp"
          android:layout_below="@+id/textView"
          android:layout_centerHorizontal="true"
          android:layout_gravity="center"
          app:lottie_autoPlay="true"
          app:lottie_colorFilter="#FFBC00"
          app:lottie_fileName="user.json"
          app:lottie_loop="true" /&gt;
  
  
      &lt;TextView
          android:id="@+id/textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="17dp"
          android:text="admin login"
          android:textAllCaps="true"
          android:textColor="#FFBA24"
          android:textSize="25dp"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/editText"
  
          android:layout_alignStart="@+id/editText2"
          android:layout_marginBottom="-247dp"
          android:text="Enter your username"
          android:textAllCaps="true"
          android:textColor="#B7BE5D"
          android:textSize="15dp" /&gt;
  
  
      &lt;EditText
          android:id="@+id/editText2"
          android:layout_width="300dp"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="183dp"
          android:ems="10"
          android:fontFamily="monospace"
          android:hint="Password"
          android:inputType="textPassword"
          android:textColorHint="#FFFFFF" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/editText2"
  
          android:layout_alignStart="@+id/editText2"
          android:text="Enter your password"
          android:textAllCaps="true"
          android:textColor="#B7BE5D"
          android:textSize="15dp" /&gt;
  
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="300dp"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="247dp"
          android:ems="10"
          android:fontFamily="monospace"
          android:hint="Username"
          android:inputType="textPersonName"
          android:textColor="#FFFFFF"
          android:textColorHint="#FFFFFF" /&gt;
  
      &lt;EditText
          android:id="@+id/Editinfo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="62dp"
          android:text="No. of attempts left : "
          android:textColor="#FFF"
          android:textSize="15dp"
          android:textStyle="italic" /&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="210dp"
          android:layout_height="45dp"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="111dp"
          android:background="@drawable/rounded_button"
          android:text="login"
          android:textAllCaps="true"
          android:textColor="#000"
          android:visibility="visible" /&gt;
  
      &lt;Button
          android:id="@+id/button"
          style="@style/Widget.AppCompat.Button.Borderless.Colored"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:background="#19193E"
          android:text="LOG IN PROBLEM? CONTACT US."
          android:textColor="#FFF"
          android:onClick="onClick"
          android:visibility="visible" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>