数据库到android,用php [英] Database to android, with php

查看:80
本文介绍了数据库到android,用php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将值从数据库发送到Android应用.我从一个教程开始,来到了这里,但是我得到了: 错误分析数据org.json.jsonexception输入的字符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.

推荐答案

发生此错误是因为没有接收到要解析的JSON数据.这可能是因为您正在尝试从onCreate()方法内部连接到Internet.从API 11开始,所有I/O功能都必须在后台线程上进行.我建议您考虑使用AsyncTask连接到服务器并下载所需的信息. 此处是指向AsyncTask的android文档的链接.基本思想很简单,任何I/O功能都可以在doInBackground()方法中使用.用户界面的任何更新,例如将文本设置在上,发生在onPostExecute()之内.阅读文档并尝试实现它.如果您仍然遇到错误,那么我们可以帮助您解决问题.

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.

这篇关于数据库到android,用php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆