title: Calling function from another activity
body: <p>I have an activity that contains all the functions for controlling my database, and I want all other activities to use to these functions when interacting with the database. Below is an example of my problem.</p>
  
  <p><strong>Clock script:</strong></p>
  
  <pre><code>public class Clock extends Activity
  {
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_clock);
  
          Data.createTable(); //&lt;&lt;&lt;
      }
          //...
  }
  </code></pre>
  
  <p><strong>Data script:</strong></p>
  
  <pre><code>public class Data extends Activity
  {
      SQLiteDatabase mydb;
      private static String DBNAME = "SHIFTS.db";
      private static String TABLE = "MY_SHIFTS"; 
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_data);
      }   
  
      public void createTable() //&lt;&lt;&lt;
      {
          try
          {
              mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
              mydb.execSQL("CREATE TABLE IF  NOT EXISTS "+ TABLE +" (ID INTEGER PRIMARY KEY, STARTDATE TEXT, ENDDATE TEXT, LENGTH INTEGER, TYPE INTEGER);");
              mydb.close();
          }
          catch(Exception e)
          {
              Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG).show();
          }
      }
      // ... lots more functions
  }
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <blockquote>
    <p>Cannot make a static reference to the non-static method createTable()
    from the type Data.</p>
  </blockquote>
  
  <p>And when I trying to make method static, it just causes more problems.</p>
  
  <p>Also if I try Data data = new Data(); data.createTable(); I get a NullPointerException.</p>
  
  <p><strong>What is the problem here?</strong></p>