Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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
0
wilko1000
Asked:
wilko1000
  • 6
  • 4
1 Solution
 
CEHJCommented:
Full stack trace please
0
 
wilko1000Author Commented:
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
0
 
wilko1000Author Commented:
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;
        }
    }




?>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
Your logger is not configured (or rather being called) in such a way as it shows the whole stack trace. It should be
0
 
wilko1000Author Commented:
Thanks for that.. and how do I configure the logger then?
0
 
CEHJCommented:
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
0
 
wilko1000Author Commented:
Eclipse has an error log Window > Show View > Error Log however when inspecting the log theres nothings bubbling up into the error log
0
 
CEHJCommented:
It's nothing to do with Eclipse - read my last comment - carefully
0
 
CEHJCommented:
Your logger is not configured (or rather being called) in such a way as it shows the whole stack trace. It should be

http://developer.android.com/reference/android/util/Log.html#getStackTraceString(java.lang.Throwable)
0
 
CEHJCommented:
:)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now