Solved

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

Posted on 2015-02-14
10
204 Views
Last Modified: 2015-03-16
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
Comment
Question by:wilko1000
  • 6
  • 4
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 40609883
Full stack trace please
0
 

Author Comment

by:wilko1000
ID: 40610005
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
 

Author Comment

by:wilko1000
ID: 40610012
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40610036
Your logger is not configured (or rather being called) in such a way as it shows the whole stack trace. It should be
0
 

Author Comment

by:wilko1000
ID: 40610150
Thanks for that.. and how do I configure the logger then?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:CEHJ
ID: 40610210
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
 

Author Comment

by:wilko1000
ID: 40610540
Eclipse has an error log Window > Show View > Error Log however when inspecting the log theres nothings bubbling up into the error log
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40610743
It's nothing to do with Eclipse - read my last comment - carefully
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 40610747
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40668884
:)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now