title: Access Database class through a fragment in android
body: <p>I'm trying to access a SQLite Database from a fragment in my "MainActivity.java" but my Database function are in another file "Database.java" so the database_fragment.xml called in the  "onCreateView" of the "MainActivity" can't access those function... Should I just put all those database function directly into the fragment class so it could see those? </p>
  
  <p>Here's the important part of my code:</p>
  
  <p>(IN MainActivity.java)</p>
  
  <pre><code>/**
   * "fragment_database", shows the database list
   */
  public static class subFragment extends Fragment {
      public static final String ARG_MENU_NUMBER = "menu_number"; // Which sub-menu
  
      public subFragment() {
          // Empty constructor required for fragment subclasses
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          int i = getArguments().getInt(ARG_MENU_NUMBER);
          View rootView;
          if(i==0){
              rootView = inflater.inflate(R.layout.fragment_database, container, false);
          }else{
              rootView = inflater.inflate(R.layout.fragment_help, container, false);  
          }
  
          return rootView;
      }
  
  
  }
  </code></pre>
  
  <p>Here is the function that the XML can't reach:</p>
  
  <p>(IN Database.java)</p>
  
  <pre><code>    public void onClick_DisplayRecords(View v) {
      displayText("Clicked display record!");
  
      Cursor cursor = myDb.getAllRows();
      displayRecordSet(cursor);
  }
  </code></pre>
  
  <p>The error message:</p>
  
  <blockquote>
    <p><strong>java.lang.IllegalStateException: Could not find a method onClick_DisplayRecords(View) in the activity class com.mtl.android.spca.MainActivity for onClick handler on view class android.widget.Button with id 'btnDisplay'</strong></p>
  </blockquote>