I am working on an app in android studio.. it currently has a login and registration system that are linked to a database and both work perfectly.

I am now trying to carry over the user id value using SESSION in php so that the activity past the login will have all the information it needs to personalize the app. To do so I made a class called Profile that, when instantiated, retrieves and stores all user information based on the id stored as a session variable.

The profile class is accompanied by it's own php file, buildprofile.php. Any class can instantiate Profile and use to to get information (hopefully).

Currently when I attempt to instantiate Profile the app crashes. There are probably 50 different things causing this and I have changed things over and over to no avail. I started a session in the login activity and stored a session variable 'id' upon login success.

The Profile constructor (based on method in a JSONParser class):

try {
        JSONObject jobj = jsonParser.getJSONFromUrl(PROFILE_URL);
        username = jobj.getString("username");
    } catch (JSONException e) {




if (isset($_SESSION['id'])){
    $query = "SELECT id,email,username,bio FROM users WHERE id = :id";    
    $query_params = array(':id' => $_SESSION['id']);

    try {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);
    catch (PDOException $ex) {
        $response["success"] = 0;
        $response["message"] = "Database Error1. Please Try Again!";

$row = $stmt->fetch();

  • For starters, json_encode() returns a string - if you don't echo it, your php script will return nothing. On another note, it's not recommended to have logic like that in a constructor.
    – Sam Dufel
    Apr 27 '15 at 2:37
  • oops. I echo'd it and it still crashes. Regardless of where the JSONobject is created Apr 27 '15 at 3:37
  • I'd suggest editing the stack trace into your question.
    – Sam Dufel
    Apr 28 '15 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.