title: Android methods in on create
body: <p>I'm new to programming and got myself stuck.I'm writing in java building an android app in eclipse.</p>
  
  <p>I've been testing an application and all my functionality has been inside my onCreateView in my fragment. I've finally got it all working but its now a bit messy. I was going to move certain parts out into their own methods. </p>
  
  <p>However when I call this method in the onCreateView it now crashes. </p>
  
  <p>The current working app looks like this:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.profile_tab, container, false);
  
  
      DatabaseHelper db = new DatabaseHelper(getActivity());
      db.createUser(new User("Sam"));
      db.createUser(new User("Gabriel"));
      username = db.getUser(IDnumber);
      displayName= (TextView) rootView.findViewById(R.id.TextViewTest);
      displayName.setText(username.getName());
  
      return rootView;
      }
  </code></pre>
  
  <p>When I amend it to this:</p>
  
  <pre><code>public void displayData(){
  
      DatabaseHelper db = new DatabaseHelper(getActivity());
      db.createUser(new User("Sam"));
      db.createUser(new User("Gabriel"));
      username = db.getUser(IDnumber);displayName= (TextView) getActivity().findViewById(R.id.TextViewTest);
      displayName.setText(username.getName());
  }
  </code></pre>
  
  <p>and call it in onCreateView, it crashes. </p>
  
  <p>I'm pretty sure its to do with the rootView which I changed to getActivity() in the second attempt but I'm not sure what else I should change it to?</p>