title: How to get data from mysql in android fragment class?
body: <p>I want to get the profile details from mysql db from fragment class. should display to textview. like student name, address, mobile etc.. I used JSON format to send the data from php.</p>
  
  <p>here is my code</p>
  
  <pre><code>public class ProfileFragment extends Fragment {
  private View parentView;
  // Session Manager Class
  SessionManager session;
  TextView student_name;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; oslist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  //URL to get JSON Array
  private String url;
  
  //JSON Node Names
  private static final String TAG_ARRAY = "student_profile";
  private static final String TAG_NAME = "student_name";
  JSONArray student_profile = null;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      //return inflater.inflate(R.layout.profile, container, false);
       parentView = inflater.inflate(R.layout.profile, container, false);
       //session.checkLogin();
       session = new SessionManager(getActivity());
       session.checkLogin();
       return parentView;
  }   
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onActivityCreated(savedInstanceState);
      oslist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      new JSONParse().execute();  
  }
  
  private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; {
  
      private ProgressDialog pDialog;
      JSONParser jParser = new JSONParser();
      private JSONObject json;
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          student_name = (TextView)getView().findViewById(R.id.studentname);
          pDialog = new ProgressDialog(getActivity());
          pDialog.setMessage("Getting Data ...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }
  
      @Override
      protected JSONObject doInBackground(String... args) {
          // get user data from session
          HashMap&lt;String, String&gt; user = session.getUserDetails();
          // name
          String emailaddr = user.get(SessionManager.KEY_NAME);
          url = "http://XXXXXXX.org/api/profile.php?emailid="+emailaddr;
          // Getting JSON from URL
          json = jParser.getJSONFromUrl(url);
          return json;
      }
  
      @Override
      protected void onPostExecute(JSONObject json) {
          pDialog.dismiss();
          try {
               // Getting JSON Array from URL
               student_profile = json.getJSONArray(TAG_ARRAY);
               for(int i = 0; i &lt; student_profile.length(); i++){
                   JSONObject c = student_profile.getJSONObject(i);
                   String student_firstname = null;
                  // Storing  JSON item in a Variable
                   String name = c.getString(student_firstname);
                   Toast.makeText(getActivity(), "name="+name, Toast.LENGTH_LONG).show();
               }
          } catch (JSONException e) {
            e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I got the error like this</p>
  
  <pre><code>12-24 09:29:44.817: W/System.err(30999): org.json.JSONException: No value for student_profile
  </code></pre>
  
  <p>12-24 09:29:44.818: W/System.err(30999):    at org.json.JSONObject.get(JSONObject.java:355)
  12-24 09:29:44.819: W/System.err(30999):    at org.json.JSONObject.getJSONArray(JSONObject.java:549)
  12-24 09:29:44.819: W/System.err(30999):    at com.tutorialsface.ResideMenuDemo.ProfileFragment$JSONParse.onPostExecute(ProfileFragment.java:89)</p>