title: How can I use data in realm from another class? (android)
body: <p>This is method stopPing() in MainActivity to save data to realm.
  If I want to use data in realm from another class, how can I coding.</p>
  
  <pre><code>private  void stopPing() {
      linkEdt.setEnabled(true);
      pingBtn.setText("Start Ping");
      isPing = false;
      count = 0;
  
      endTime = getTime();
  
      /* Open the Realm for the UI thread. */
      realm = Realm.getInstance(realmConfig);
  
      /* All writes must be wrapped in a transaction to facilitate safe multi threading */
      realm.beginTransaction();
  
      Ping ping = realm.createObject(Ping.class);
  
      /* Add ip */
      ping.set_ip(ip);
  
      /* Add start time */
      ping.set_startTime(startTime);
  
      /* Add end time. */
      ping.set_endTime(endTime);
  
      /* Add down amount */
      ping.set_downAmount(downtime);
  
      /* Add ping speed time. */
      PingTime pingtime = realm.createObject(PingTime.class);
  
      for(Double speedTime : speedList){
          pingtime.time = speedTime;
          ping.get_times().add(pingtime);
      }
  
      /* Add time. */
      for(String time : timeList){
          pingtime.pingTime = time;
          ping.get_pingTime().add(pingtime);
      }
  
      realm.commitTransaction();
  
      /* stop handler. */
      this.mHandler.removeCallbacks(m_Runnable);
  }
  </code></pre>
  
  <p>When I want to query in another class it has error with realm -->> io.realm.Realm.allObjects(java.lang.Class)' on a null object reference</p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_ping_list);
  
  
      for (Ping pers : realm.allObjects(Ping.class)) {
  
          String startT, endT;
          if (pers.get_stratTime() == null) {
              startT = "None";
          } else {
              startT = pers.get_stratTime();
          }
  
          if (pers.get_endTime() == null) {
              endT = "None";
          } else {
              endT = pers.get_endTime();
          }
  
          status += "Start time: " + startT + "\n End time: " + endT + "\n";
          status += "Ping total: " + pers.get_times().size() + "\n";
          status += "Down amount: " + pers.get_downAmount() + " time.\n";
  
          for (int i = 0; i &lt; pers.get_times().size(); i++) {
              double speed = pers.get_times().get(i).time;
              String time = pers.get_pingTime().get(i).pingTime;
  
              status += "time (" + (i + 1) + "): " + speed + " ms. at " + time + ".\n";
          }
  
      }
  
      System.out.println(status);
  }
  </code></pre>