0

i'm trying to send values from a database to an Android app. I started from a tutorial and got here, but i'm getting: "error parsing data org.json.jsonexception end of input at character 0 of" I probably have other errors, but this is the first one i get when running the app.

edit: i can't delete this question, but it is no longer relevant. The code had mistakes which i corrected meanwhile. The answers, while helpful, were not the solution. this is probably my fault, as the question was formulated badly.

1
  • Have you changed index.php ? Can you see an output now? Commented Jun 4, 2013 at 16:45

3 Answers 3

1

The error is occurring because there is no JSON data being received to parse. Likely this is because you are trying to connect to the internet from within your onCreate() method. Since API 11, all I/O functions need to take place on a background thread. I suggest you look into using AsyncTask to connect to your server and download the information you need. Here is a link to the android docs for AsyncTask. The basic idea is simple, any I/O functions go in the doInBackground() method. Any updating of the UI, e.g. setting the text on a TextView, takes place within onPostExecute(). Read the documentation and try to implement it. If you're still getting errors then, we can help you fix it.

Sign up to request clarification or add additional context in comments.

2 Comments

mm... both the database and the app run on the same machine. from what i understand, the JSON parser is sent this: "10.0.2.2/android_login_api". The app is run the emulator that comes with eclipse.
It does not matter that you are connecting to a localhost. You are using a network operation which is an I/O function and must be run on a background thread.
0

From what you say is in index.php,

    } else if ($tag == 'get_data_tag'){
  // Request type is get data

    $Channel_id = $_POST['Channel_id'];
    $Temp_value = $_POST['Temp_value'];

//check for the value for the specified channel
    $value = $db->getDataByChannelId($Channel_id, $Temp_value);

//this is where the data should be sent to the app
    $response_data["success"] = 1;
    $response_data["Channel_id"] = $value["Channel_id"];
    $response_data["Temp_value"] = $value["Temp_value"];
    echo json_encode($response_data);
}

PHP may be returning a parse error (because of the else without an if), and then the JSON library (in your Java/Android code) can't read something like "Parse Error: " as JSON which would lead it to throw that error.

Disregard this if you just omitted the other bits of code from your question.

1 Comment

yes, there are two more cases, two more tags, and i didn't include those. They handle the login and registration of users, and they work. Thanks for the answer though
0

Just try this example in the below link and try to do it in the same manner.

http://android-am.blogspot.in/2012/10/android-login-screen-by-connecting-to.html

1 Comment

thanks, i'll see what i can learn from that, but i already have a working login and register sequence, which i made using another tutorial. now i'm trying to get values from another table to display in a text field in my app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.