Link to home
Start Free TrialLog in
Avatar of wilko1000
wilko1000

asked on

Eclipse error message: String cannot be converted to JSONObject after laptop rebuild

HI

I get the following error when i attempt to log into my local emulator ever since i rebuilt my laptop (no code change has been made):

String cannot be converted to JSONObject

When i go into dubug mode in Eclipse the excetion gets caught here:

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

            // Making HTTP request
            try {
                  // defaultHttpClient
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
                  httpPost.setEntity(new UrlEncodedFormEntity(params));

                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();

            } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
            } catch (ClientProtocolException e) {
                  e.printStackTrace();
            } catch (IOException e) {
                  e.printStackTrace();
            }

            try {
                  BufferedReader reader = new BufferedReader(new InputStreamReader(
                              is, "iso-8859-1"), 8);
                  StringBuilder sb = new StringBuilder();
                  String line = null;
                  while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                  }
                  is.close();
                  json = sb.toString();
                  Log.e("JSON", json);
            } catch (Exception e) {
                  Log.e("Buffer Error", "Error converting result " + e.toString());
            }

I can see whatever string i enter being passed to the REST service a response returned and then validated throughout the login cycle.

It must be something environmental as it was working before i rebuilt laptop but once i set back up again on laptop with no code change made, the error started occurring.
Can anyone explain what it happening?

Note:
No change has been made to the REST service, java code or database prior to or after the rebuild
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Full stack trace please
Avatar of wilko1000
wilko1000

ASKER

02-14 19:04:35.821: E/JSON(384): <tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec'
 align='center'>0.0130</td><td bgcolor='#eeeeec' align='right'>168184</td><td bgcolor='#eeeeec'>DB_CONNECT->
connect(  )</td><td title='C:\wamp\www\RESTApi\include\DB_Functions.php' bgcolor='#eeeeec'
>..\DB_Functions.php<b>:</b>13</td></tr>
02-14 19:04:35.821: E/JSON(384): <tr><td bgcolor='#eeeeec'
align='center'>4</td><td bgcol
02-14 19:04:35.831: E/JSON Parser(384): Error parsing data org.json.JSONException:
 Value <br of type java.lang.String cannot be converted to JSONObject
heres the DB_Functions PHP that gets called when hitting the logon button

<?php

class DB_Functions {

    private $db;

    //put your code here
    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $this->db = new DB_Connect();
        $this->db->connect();
    }

    // destructor
    function __destruct() {
       
    }


    /**
     * Get user by email and password
     */
    public function getUserByEmailAndPassword($email, $password) {
        $result = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error());
        // check for result
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            $result = mysql_fetch_array($result);
            $salt = $result['salt'];
            $encrypted_password = $result['encrypted_password'];
            $hash = $this->checkhashSSHA($salt, $password);
            // check for password equality
            if ($encrypted_password == $hash) {
                // user authentication details are correct
                return $result;
            }
        } else {
            // user not found
            return false;
        }
    }

    /**
     * Check user is existed or not
     */
    public function isUserExisted($email) {
        $result = mysql_query("SELECT email from users WHERE email = '$email'");
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            // user existed
            return true;
        } else {
            // user not existed
            return false;
        }
    }




?>
Your logger is not configured (or rather being called) in such a way as it shows the whole stack trace. It should be
Thanks for that.. and how do I configure the logger then?
Well i don't do Android. You need to find out how to get the logger to print a stack trace. Check the API docs
Eclipse has an error log Window > Show View > Error Log however when inspecting the log theres nothings bubbling up into the error log
It's nothing to do with Eclipse - read my last comment - carefully
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)