title: Change Password Activity
body: <p>I have a problem in this app, it show me "Unfortunately, app has stopped"</p>
  
  <p>MainActivity.class</p>
  
  <pre><code>        package ahmedchtn.stockmanager;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity {
      EditText username;
      EditText password;
      Button loginbutton;
      Button bpasschange;
  
      int counter = 3;
      String username_string  ;
      String password1 = "";
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          username = (EditText) findViewById(R.id.identifer);
          password = (EditText) findViewById(R.id.password);
          loginbutton = (Button) findViewById(R.id.bLogin);
          bpasschange = (Button) findViewById(R.id.bCh);
          username_string = "admin";
          if (password1 == "") {
              password1 = "admin";
          } else {
              Intent intent4 = getIntent();
              password1 = intent4.getStringExtra("oldpassw");
          }
          bpasschange.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View view) {
  
                  Intent intentoldpass = new Intent(MainActivity.this, PasswordChange.class);
                  intentoldpass.putExtra("oldpassw", password1);
  
                  Intent intentpasschan = new Intent(getApplicationContext(), PasswordChange.class);
                  startActivity(intentpasschan);
  
              }
          });
  
          loginbutton.setOnClickListener(new View.OnClickListener() {
                                             @Override
                                             public void onClick(View view) {
  
                                                 if (username.getText().toString().equals(username_string) &amp;&amp;
                                                         password.getText().toString().equals(password1)) {
                                                     Toast.makeText(getApplicationContext(),
                                                             "Redirecting...", Toast.LENGTH_SHORT).show();
                                                     Intent iop = new Intent(getApplicationContext(), ManagementPage.class);
                                                     startActivity(iop);
  
  
                                                 } else {
                                                     Toast.makeText(getApplicationContext(),
                                                             "Wrong Entries", Toast.LENGTH_SHORT).show();
                                                     counter--;
                                                     if (counter == 0) {
                                                         loginbutton.setEnabled(false);
                                                     }
  
  
                                                 }
                                             }
                                         }
  
          );
  
  
      }
  }
  </code></pre>
  
  <p>PasswordChange.class</p>
  
  <pre><code>    package ahmedchtn.stockmanager;
  
  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 PasswordChange extends AppCompatActivity {
      Button bchange;
      EditText oldpassword;
      EditText newpassword;
      String oldpass;
      String newpass;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_password_change);
  
  
          bchange = (Button) findViewById(R.id.bChange2);
          oldpassword = (EditText) findViewById(R.id.old_password);
          newpassword = (EditText) findViewById(R.id.new_password);
          bchange.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent ioldpass = getIntent();
                  oldpass = ioldpass.getStringExtra("oldpassw");
                  if (oldpass == (oldpassword.getText().toString())) {
                      newpass = newpassword.getText().toString();
                      Intent intentnew = new Intent(PasswordChange.this, MainActivity.class);
                      intentnew.putExtra("passnew", newpass);
                      startActivity(intentnew);
  
                      Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                      startActivity(intent);
                  }
              }
          });
      }
  
  }
  </code></pre>
  
  <p>I think that the problem is with the intents..
  Thanks in advance for your help !
  Is there any other solutions </p>
  
  <p>The logcat</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                    java.lang.NullPointerException
                        at ahmedchtn.stockmanager.MainActivity$2.onClick(MainActivity.java:46)
                        at android.view.View.performClick(View.java:4439)
                        at android.widget.Button.performClick(Button.java:139)
                        at android.view.View$PerformClick.run(View.java:18395)
                        at android.os.Handler.handleCallback(Handler.java:725)
                        at android.os.Handler.dispatchMessage(Handler.java:92)
                        at android.os.Looper.loop(Looper.java:176)
                        at android.app.ActivityThread.main(ActivityThread.java:5317)
                        at java.lang.reflect.Method.invokeNative(Native Method)
                        at java.lang.reflect.Method.invoke(Method.java:511)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                        at dalvik.system.NativeStart.main(Native Method)
  Application terminated.
  </code></pre>
  
  <p>Xml Codes 
  activity_main.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="ahmedchtn.stockmanager.MainActivity"&gt;
  
  
      &lt;EditText
          android:id="@+id/identifer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/activity_vertical_margin"
          android:hint="@string/enter_your_id" /&gt;
  
      &lt;EditText
          android:id="@+id/password"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/activity_vertical_margin"
          android:hint="@string/enter_your_password"
          android:inputType="textPassword" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:weightSum="1"&gt;
  
          &lt;Button
              android:id="@+id/bLogin"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="0.5"
              android:text="@string/login" /&gt;
  
          &lt;Button
              android:id="@+id/bCh"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="changer passe" /&gt;
  
      &lt;/LinearLayout&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>activity_password_change.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_password_change"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="ahmedchtn.stockmanager.PasswordChange"&gt;
  
      &lt;EditText
          android:id="@+id/old_password"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/activity_vertical_margin"
          android:hint="@string/enter_your_old_password" /&gt;
  
      &lt;EditText
          android:id="@+id/new_password"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="@dimen/activity_vertical_margin"
          android:hint="@string/enter_your_new_password" /&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_margin="@dimen/activity_vertical_margin"
          android:weightSum="1"&gt;
  
          &lt;Button
              android:id="@+id/bChange2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="@dimen/activity_vertical_margin"
              android:layout_weight="0.5"
              android:text="@string/confirm" /&gt;
  
          &lt;Button
              android:id="@+id/main_page"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="@dimen/activity_vertical_margin"
              android:layout_weight="0.5"
              android:text="@string/main_page" /&gt;
  
  
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Manifest </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="ahmedchtn.stockmanager"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".ManagementPage"
              android:parentActivityName=".MainActivity" /&gt;
          &lt;activity android:name=".ProductsSearch" /&gt;
          &lt;activity android:name=".ProductsCommand" /&gt;
          &lt;activity
              android:name=".Editor"
              android:parentActivityName=".ProductsList" /&gt;
          &lt;activity android:name=".ProductsList" /&gt;
  
          &lt;provider
              android:name=".data.ProductProvider"
              android:authorities="ahmedchtn.stockmanager"
              android:exported="false" /&gt;
  
          &lt;activity android:name=".PasswordChange"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I have updated my code</p>