title: Call Method - Android Studio
body: <p>I'm basically trying to get information from another activity. Therefore i would need to call the activity. I use;</p>
  
  <pre><code>Adduser adduser = new AddUser();
  </code></pre>
  
  <p>but when i add it, the application keeps force closing? any ideas?</p>
  
  <p>MainActivity;</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity{
  
   //AddUser adduser = new AddUser(); // HERE
  
     // private Realm realm;
     // private RealmConfiguration realmConfig;
  Button btnadd;
  ListView listuser;
  ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  ArrayAdapter&lt;String&gt; adapter;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
      setContentView(R.layout.activity_main);
    //  RealmConfiguration config = new RealmConfiguration.Builder(this).build();
     // Realm.setDefaultConfiguration(config);
      //getNames();
  
      //Add User Button
      btnadd = (Button) findViewById(R.id.btnAdd);
      listuser = (ListView) findViewById(R.id.listUser);
     // adduser.txtName = (EditText) findViewById(R.id.txtName);
      adapter =new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
      listuser.setAdapter(adapter);
  
      //Button Event
      btnadd.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (v == btnadd) {
                  Intent addUser = new Intent(getApplicationContext(), AddUser.class);
                  startActivityForResult(addUser,1);
              }
          }
      });
  }
  /*void getNames()
  {
      list.add(adduser.txtName.getText().toString());
  }*/
  @Override
  protected  void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == 1 &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null) {
          adapter.add(data.getStringExtra("name"));
          adapter.notifyDataSetChanged();
      }
  }
  }
  </code></pre>
  
  <p>AddUser:</p>
  
  <pre><code>public class AddUser extends AppCompatActivity {
  Button btnback, btnsave;
  EditText txtName, txtEmail, txtPhone, txtAddress;
  String n1;
  int no1;
  Realm realm1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.adduser);
     // Realm realm = Realm.getInstance(this);
      //EditText
      txtName=(EditText)findViewById(R.id.txtName);
      txtEmail=(EditText)findViewById(R.id.txtEmail);
      txtPhone=(EditText)findViewById(R.id.txtPhone);
      txtAddress=(EditText)findViewById(R.id.txtAddress);
      //Button
      btnback =(Button) findViewById(R.id.btnBack);
      btnsave = (Button)findViewById(R.id.btnSave);
      //Button Event
      btnback.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(v == btnback){
                  Intent main = new Intent(getApplicationContext(), MainActivity.class);
                  startActivity(main);
              }
          }
      });
  
      btnsave.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (v == btnsave) {
  
                  Intent result = new Intent();
                  result.putExtra("name",txtName.getText().toString());
                  setResult(RESULT_OK, result);
  
                  Log.v("Name", txtName.getText().toString());
                  Log.v("Email", txtEmail.getText().toString());
                  Log.v("Phone", txtPhone.getText().toString());
                  Log.v("Address", txtAddress.getText().toString());
  //main.list.add(txtName.getText().toString());
                  //UPDATE
                  /*realm1.beginTransaction();
                  //Saves the input data
                 User user = realm1.createObject(User.class);
                 user.setName(txtName.getText().toString());
                 user.setAddress(txtAddress.getText().toString());
                 user.setEmail(txtEmail.getText().toString());
                 n1 = txtPhone.getText().toString();
                 no1 = Integer.parseInt(n1);
                  //COMMIT
                 realm1.commitTransaction();
                 */
                  Toast.makeText(AddUser.this, "User has been added.", Toast.LENGTH_LONG).show();
  
                  //Start Activity
                  Intent save = new Intent(getApplicationContext(), MainActivity.class);
                  startActivity(save);
  
              }
          }
      });
  }
  
  }
  </code></pre>
  
  <p>LOG:</p>
  
  <pre><code>03-31 09:38:26.030 2831-2831/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.example.scott.addressbook, PID: 2831
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.scott.addressbook/com.example.scott.addressbook.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:135)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
                                                   at com.example.scott.addressbook.MainActivity.getNames(MainActivity.java:51)
                                                   at com.example.scott.addressbook.MainActivity.onCreate(MainActivity.java:30)
                                                   at android.app.Activity.performCreate(Activity.java:5937)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:144) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:135) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5221) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
  03-31 09:38:26.060 941-941/? E/EGL_emulation: tid 941: eglCreateSyncKHR(1237): error 0x3004 (EGL_BAD_ATTRIBUTE)
  </code></pre>
  
  <p>I've noticed this:<br>
      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method      'android.text.Editable android.widget.EditText.getText()' on a null object reference</p>
  
  <p>Null object?</p>
  
  <p>I've searched google and everyone is saying that's the way to do it? little bit confused on something simple lol. Thanks in advance!</p>