Solved

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

Posted on 2015-02-14
10
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mySMS seems stuck after install 7 52
jmeter usage 4 68
Which Oppo n Samsung models are 64bit 6 55
a successful app 7 29
If your app took Google’s lash recently, here are the 5 most likely reasons.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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