title: How to call Java class in another class
body: <p>I'm new in Java and Android and I have lots of problems. I Create one Java class call EmptyField.java, this class has 2 methods: Login Empty and Create Empty.
  I have another java file called Loginactivity.java. In Loginactivity I want to call EmptyField's class but I'm not able to do it. This is my code.</p>
  
  <p>Emptyfield.java</p>
  
  <pre><code>package com.example.prenotazione_esame;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.EditText;
  
  public class EmptyField extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);     
      }
  
      public String LoginEmpty(){
  
          EditText login_text = (EditText) findViewById(R.id.UserName);
          EditText password_text = (EditText) findViewById(R.id.Password);
          if ((login_text.getText().toString().equals(""))|| (password_text.getText().toString().equals(""))){
              return "Empty" ;
          }
          else{
              return "Full";
          }
      }
      public String CreateEmpty(){
  
          EditText login_text = (EditText) findViewById(R.id.UserName);
          EditText password_text = (EditText) findViewById(R.id.Password);
          EditText conferma_text = (EditText) findViewById(R.id.Conferma);
          if ((login_text.getText().toString().equals(""))|| (password_text.getText().toString().equals("")) || (conferma_text.getText().toString().equals(""))){
              return "Empty" ;
          }
          else{
              return "Full";
          }
      }
  }
  </code></pre>
  
  <p>this is Loginactivity.java:</p>
  
  <pre><code>package com.example.prenotazione_esame;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  import android.view.View.OnClickListener;
  
  public class LoginActivity extends Activity {
  
      private LoginDataBase dbLogin;
      EmptyField emptyf = new EmptyField();
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          Button button_crea = (Button) findViewById(R.id.Create);
          button_crea.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v){
                  openCreateAccount();
              }
          });
  
          dbLogin = new LoginDataBase(this);
  
          Button button_login = (Button) findViewById(R.id.Login);
          button_login.setOnClickListener(new View.OnClickListener() {        
              @Override
              public void onClick(View v) {
                  executeLogin();
  
              }
          });
  
      }
     private void openCreateAccount(){
         Intent intent_crea = new Intent(this, CreateAccountActivity.class);
         startActivity(intent_crea);
      }
     private void executeLogin(){
  
         //EmptyField emptyf = new EmptyField();
         String a=emptyf.LoginEmpty();
         Toast toast = Toast.makeText(this,a, Toast.LENGTH_SHORT);
         toast.show();
  
  
  
     }
  }
  </code></pre>
  
  <p>I start my app on the emulator and, when it try to call EmptyField class, the app crash. can ypou help me? Thank you.</p>
  
  <p>my logcat:</p>
  
  <pre><code>05-08 09:24:49.070: E/AndroidRuntime(1162): FATAL EXCEPTION: main
  05-08 09:24:49.070: E/AndroidRuntime(1162): Process: com.example.prenotazione_esame, PID: 1162
  05-08 09:24:49.070: E/AndroidRuntime(1162): java.lang.NullPointerException
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at com.example.prenotazione_esame.LoginActivity.executeLogin(LoginActivity.java:55)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at    com.example.prenotazione_esame.LoginActivity.access$1(LoginActivity.java:44)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at com.example.prenotazione_esame.LoginActivity$2.onClick(LoginActivity.java:34)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.view.View.performClick(View.java:4438)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.view.View$PerformClick.run(View.java:18422)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.os.Handler.handleCallback(Handler.java:733)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.os.Handler.dispatchMessage(Handler.java:95)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.os.Looper.loop(Looper.java:136)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at java.lang.reflect.Method.invoke(Method.java:515)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  05-08 09:24:49.070: E/AndroidRuntime(1162):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>here my empyfield.java. Now it run. Thank you.</p>
  
  <pre><code>package com.example.prenotazione_esame;
  
  
  import android.widget.EditText;
  
  public class EmptyField{
  
      public String LoginEmpty(EditText x, EditText y){
  
          if ((x.getText().toString().equals(""))|| (y.getText().toString().equals(""))){
              return "Empty" ;
          }
          else{
              return "Full";
          }
      }
      public String CreateEmpty(EditText x, EditText y, EditText z){
  
          if ((x.getText().toString().equals(""))|| (y.getText().toString().equals("")) || (z.getText().toString().equals(""))){
              return "Empty" ;
          }
          else{
              return "Full";
          }
      }
  }
  </code></pre>