Solved

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

Posted on 2015-02-14
10
227 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

821 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