无法在我从MySQL的Andr​​oid应用程序列表中的数据 [英] Cannot list the data in my android application from Mysql

查看:111
本文介绍了无法在我从MySQL的Andr​​oid应用程序列表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我在Android开发新的。我试图做我的Andr​​oid应用程序的数据库CRUD操作。
                我可以成功地插入使用PHP和JSON解析了它。当插入到数据库中的数据的数据的mysql.Am,下一个活动应该是上市data.The问题是没有数据进入我的上市活动。只有活动即将没有数据。好心帮了我。                另外我的Java code为上市产品是                公共类AllProductsActivity扩展ListActivity {                    //进度对话框
                    私人ProgressDialog pDialog;                    //创建JSON解析器对象
                    JSONParser jParser =新JSONParser();                    ArrayList的<&HashMap的LT;字符串,字符串>>产品列表;                    // URL获得所有产品清单
                    私人静态字符串url_all_products =htt​​p://10.0.2.2/get_all_products.php;                    // JSON节点名称
                    私有静态最后弦乐TAG_SUCCESS =成功;
                    私有静态最后弦乐TAG_PRODUCTS =产品;
                    私有静态最后弦乐TAG_PID =PID;
                    私有静态最后弦乐TAG_NAME =名;                    //产品JSONArray
                    JSONArray产品= NULL;                    @覆盖
                    公共无效的onCreate(捆绑savedInstanceState){
                        super.onCreate(savedInstanceState);
                        的setContentView(R.layout.all_products);                        //为哈希映射的ListView
                        产品列表=新的ArrayList<&HashMap的LT;字符串,字符串>>();                        //装载产品在后台线程
                        新LoadAllProducts()执行();                        //获取列表视图
                        ListView控件LV = getListView();                        //在选课单品
                        //启动编辑产品屏幕
                        lv.setOnItemClickListener(新OnItemClickListener(){                            @覆盖
                            公共无效onItemClick(适配器视图<>母公司,观景,
                                    INT位置,长的id){
                                //从选定的ListItem得到的值
                                字符串的pid =((的TextView)view.findViewById(R.id.pid))的getText()。
                                        的ToString();                                //开始新意图
                                在意向=新意图(getApplicationContext()
                                        EditProductActivity.class);
                                //发送到PID下一个活动
                                in.putExtra(TAG_PID,PID);                                //开始新的活动,期待一些回响应
                                startActivityForResult(在100);
                            }
                        });                    }                    //从编辑产品的活动响应
                    @覆盖
                    保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
                        super.onActivityResult(要求code,结果code,数据);
                        //如果结果code 100
                        如果(结果code == 100){
                            //如果结果code 100接收
                            //意味着用户编辑/删除产品
                            //重新载入该画面
                            意向意图= getIntent();
                            完();
                            startActivity(意向);
                        }                    }                    / **
                     *背景异步任务以通过HTTP请求负载的所有产品
                     * * /
                    类LoadAllProducts扩展的AsyncTask<字符串,字符串,字符串> {                        / **
                         *启动后台线程显示进度对话框之前
                         * * /
                        @覆盖
                        在preExecute保护无效(){
                            super.on preExecute();
                            pDialog =新ProgressDialog(AllProductsActivity.this);
                            pDialog.setMessage(加载产品请稍候......);
                            pDialog.setIndeterminate(假);
                            pDialog.setCancelable(假);
                            pDialog.show();
                        }                        / **
                         *让所有的产品网址
                         * * /
                        保护字符串doInBackground(字符串参数... args){
                            //大厦参数
                            清单<&的NameValuePair GT; PARAMS =新的ArrayList<&的NameValuePair GT;();
                            // URL从获取JSON字符串
                            JSONObject的JSON = jParser.makeHtt prequest(url_all_products,GET,则params);                            //检查JSON效应初探日志的猫
                            Log.d(所有产品,json.toString());                            尝试{
                                //检查成功TAG
                                INT成功= json.getInt(TAG_SUCCESS);                                如果(成功== 1){
                                    发现//产品
                                    //获取产品阵列
                                    产品= json.getJSONArray(TAG_PRODUCTS);                                    //产品通过所有循环
                                    的for(int i = 0; I< products.length();我++){
                                        JSONObject的C = products.getJSONObject(I)                                        //存储在变量中的每个JSON项目
                                        字符串ID = c.getString(TAG_PID);
                                        字符串名称= c.getString(TAG_NAME);                                        //创建新的HashMap
                                        HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();                                        //将每个子节点的HashMap键=>值
                                        map.put(TAG_PID,身份证);
                                        map.put(TAG_NAME,名);                                        //添加HashList到ArrayList的
                                        productsList.add(地图);
                                    }
                                }其他{
                                    //没有发现产品
                                    //启动添加新产品活动
                                    意图I =新意图(getApplicationContext()
                                            NewProductActivity.class);
                                    //关闭所有previous活动
                                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    startActivity(ⅰ);
                                }
                            }赶上(JSONException E){
                                e.printStackTrace();
                            }                            返回null;
                        }                        / **
                         *在完成后台任务之后辞退进度对话框
                         * ** /
                        保护无效onPostExecute(字符串FILE_URL){
                            //让所有的产品后,关闭该对话框
                            pDialog.dismiss();
                            //从后台线程更新界面
                            runOnUiThread(新的Runnable(){
                                公共无效的run(){
                                    / **
                                     *更新解析JSON数据到ListView控件
                                     * * /
                                    ListAdapter适配器=新SimpleAdapter(
                                            AllProductsActivity.this,产品列表,
                                            R.layout.list_item,新的String [] {TAG_PID,
                                                    TAG_NAME},
                                            新的INT [] {R.id.pid,R.id.name});
                                    //更新列表视图
                                    setListAdapter(适配器);
                                }
                            });                        }                    }                    }
                在这里,在这个code,想显示三个数据,名称,价格,描述。PHP的文件
                从数据库中检索的mysql中的数据,而字符串转换成JSON对象。然后我的Java code将调用JSON类,并列出数据。我可以成功地插入使用PHP和JSON解析了它。当插入到数据库中的数据的数据的mysql.Am,下一个活动应该是上市data.The问题是没有数据进入我的上市活动。只有活动即将没有数据。好心帮了我。
 我解析或转换JSON类是如下            这是我的JSON解析code。在这个code首先我创建了一个功能从URL获取JSON。那么code通过使用if,else语句使对GET和POST方法的HTTP请求。在其他方法我把code为get方法。我将它改成JSON对象,以及更高版本的Andr​​oid code将调用它,并在活动中显示出来..
        我用了一个JSON解析器类从URL获取JSON。此类支持两个HTTP请求方法GET和POST从URL获取JSON。
    由于我们通过HTTP调用获得JSON,我增加了异步法对后台线程HTTP调用。添加follwing方法在主活动课                公共JSONParser(){                    }                    //函数得到JSON的网址
                    //通过HTTP POST或GET mehtod
                    公众的JSONObject makeHtt prequest(URL字符串,字符串的方法,
                            清单<&的NameValuePair GT; PARAMS){                        //使HTTP请求
                        尝试{                            //检查请求的方法
                            如果(方法==POST){
                                //请求方法是POST
                                // defaultHttpClient
                                DefaultHttpClient的HttpClient =新DefaultHttpClient();
                                HttpPost httpPost =新HttpPost(URL);
                                httpPost.setEntity(新UrlEn codedFormEntity(PARAMS));                                HTT presponse HTT presponse = httpClient.execute(httpPost);
                                HttpEntity httpEntity = HTT presponse.getEntity();
                                是= httpEntity.getContent();                            }否则如果(方法==GET){
                                //请求方法是GET
                                DefaultHttpClient的HttpClient =新DefaultHttpClient();
                                字符串中的paramString = URLEn codedUtils.format(参数,可以UTF-8);
                                网址+ =? +中的paramString;
                                HTTPGET HTTPGET =新HTTPGET(URL);                                HTT presponse HTT presponse = httpClient.execute(HTTPGET);
                                HttpEntity httpEntity = HTT presponse.getEntity();
                                是= httpEntity.getContent();
                            }                        }赶上(UnsupportedEncodingException五){
                            e.printStackTrace();
                        }赶上(ClientProtocolException E){
                            e.printStackTrace();
                        }赶上(IOException异常五){
                            e.printStackTrace();
                        }                        尝试{
                            读者的BufferedReader =新的BufferedReader(新的InputStreamReader(
                                    是,ISO-8859-1),8);
                            StringBuilder的SB =新的StringBuilder();
                            串线= NULL;
                            而((行= reader.readLine())!= NULL){
                                sb.append(行+\\ n);
                            }
                            is.close();
                            JSON = sb.toString();
                        }赶上(例外五){
                            Log.e(缓冲区错误,错误转换结果+ e.toString());
                        }                        //尝试分析字符串到一个JSON对象
                        尝试{
                            jObj =新的JSONObject(JSON);
                        }赶上(JSONException E){
                            Log.e(JSON解析器,错误分析数据+ e.toString());
                        }                        //返回JSON字符串
                        返回jObj;                    }
                }
            这是我的JSON解析code。在这个code首先我创建了一个功能从URL获取JSON。那么code通过使用if,else语句使对GET和POST方法的HTTP请求。在其他方法我把code为get方法。我将它改成JSON对象,以及更高版本的Andr​​oid code将调用它,并在活动中显示出来..
    我用了一个JSON解析器类从URL获取JSON。此类支持两个HTTP请求方法GET和POST从URL获取JSON。
由于我们通过HTTP调用获得JSON,我增加了异步法对后台线程HTTP调用。添加follwing方法在主活动课

三江源结果
    @马尼什Dubay结果
    据我从你得到了我的指令改变了JSONObject.still没什么code将在我的Allproducts活动显示。
    MYT logcat的错误,当我加入Log.v(JSON字符串,结果=>+ JSON);

  3月3日至10日:49:54.491:W / System.err的(1559):org.json.JSONException:产品没有价值
3月3日至10日:49:54.491:W / System.err的(1559):在org.json.JSONObject.get(JSONObject.java:354)
3月3日至10日:49:54.508:I /编舞(1559):97跳过帧!该应用程序可能会做它的主线程的工作太多了。
3月3日至10日:49:54.528:W / System.err的(1559):在org.json.JSONObject.getJSONArray(JSONObject.java:548)
3月3日至10日:49:54.558:W / System.err的(1559):在com.example.sampleapp2.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:141)
3月3日至10日:49:54.618:W / System.err的(1559):在com.example.sampleapp2.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
3月3日至10日:49:54.668:W / System.err的(1559):在android.os.AsyncTask $ 2.call(AsyncTask.java:287)
3月3日至10日:49:54.698:W / System.err的(1559):在java.util.concurrent.FutureTask.run(FutureTask.java:234)
3月3日至10日:49:54.718:W / System.err的(1559):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)
3月3日至10日:49:54.748:W / System.err的(1559):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
3月3日至10日:49:54.788:W / System.err的(1559):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:573)
3月3日至10日:49:54.898:I /编舞(1559):84跳过帧!该应用程序可能会做它的主线程的工作太多了。
3月3日至10日:49:54.958:W / System.err的(1559):在java.lang.Thread.run(Thread.java:841)
3月3日至10日:49:55.038:I /编舞(1559):83跳过帧!该应用程序可能会做它的主线程的工作太多了。
3月3日至10日:49:55.168:I /编舞(1559):跳过212帧!该应用程序可能会做它的主线程的工作太多了。
3月3日至10日:49:55.218:I /编舞(1559):55跳过帧!该应用程序可能会做它的主线程的工作太多了。


解决方案

 错误解析数据org.json.JSONException:java.lang.String类型的值get_all_products.php不能转换为的JSONObject

指出,你不必在你的resopnse从Web服务来有效的JSON字符串。这个 jObj = isValidJson(JSON)的监守; 不返回任何JSON对象

在您的上述code,在

  JSON = sb.toString();

您正在创建命名为JSON字符串和字符串生成器对象值分配给它。但是你说logcat中,你是不是在下面一行geeting有效的JSON字符串,

  {尝试
                        jObj =新的JSONObject(JSON);
                    }赶上(JSONException E){
                        Log.e(JSON解析器,错误分析数据+ e.toString());
                    }

因此​​,它会抛出错误有关分析JSON字符串。在这种情况下,你必须检查是否从服务器的响应去牛逼有效的JSON字符串。使上述code一些变化:

 公共布尔isValidJson(字符串测试)
{
    尝试{
        新的JSONObject(测试);
        返回true;
    }赶上(JSONException前){
        返回false;
    }
}

和,在code:

  {尝试
       如果(isValidJson(JSON)
    {
      jObj =新的JSONObject(JSON);
    }赶上(JSONException E){
              Log.e(JSON解析器,错误分析数据+ e.toString());
          }
    }

                Am new in Android development. I trying to do database CRUD  operation in my android application.
                I can successfully insert the data to the mysql.Am using PHP and JSON parsing for it.When the data inserted into database, the next activity should be listing the data.The problem is no data is coming into my listing activity. only the Activity is coming without data. kindly help me .



                Also  my java code for the listing products is



                public class AllProductsActivity extends ListActivity {

                    // Progress Dialog
                    private ProgressDialog pDialog;

                    // Creating JSON Parser object
                    JSONParser jParser = new JSONParser();

                    ArrayList<HashMap<String, String>> productsList;

                    // url to get all products list
                    private static String url_all_products = "http://10.0.2.2/get_all_products.php";

                    // JSON Node names
                    private static final String TAG_SUCCESS = "success";
                    private static final String TAG_PRODUCTS = "products";
                    private static final String TAG_PID = "pid";
                    private static final String TAG_NAME = "name";

                    // products JSONArray
                    JSONArray products = null;

                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.all_products);

                        // Hashmap for ListView
                        productsList = new ArrayList<HashMap<String, String>>();

                        // Loading products in Background Thread
                        new LoadAllProducts().execute();

                        // Get listview
                        ListView lv = getListView();

                        // on seleting single product
                        // launching Edit Product Screen
                        lv.setOnItemClickListener(new OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                                // getting values from selected ListItem
                                String pid = ((TextView) view.findViewById(R.id.pid)).getText()
                                        .toString();

                                // Starting new intent
                                Intent in = new Intent(getApplicationContext(),
                                        EditProductActivity.class);
                                // sending pid to next activity
                                in.putExtra(TAG_PID, pid);

                                // starting new activity and expecting some response back
                                startActivityForResult(in, 100);
                            }
                        });

                    }

                    // Response from Edit Product Activity
                    @Override
                    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                        super.onActivityResult(requestCode, resultCode, data);
                        // if result code 100
                        if (resultCode == 100) {
                            // if result code 100 is received
                            // means user edited/deleted product
                            // reload this screen again
                            Intent intent = getIntent();
                            finish();
                            startActivity(intent);
                        }

                    }

                    /**
                     * Background Async Task to Load all product by making HTTP Request
                     * */
                    class LoadAllProducts extends AsyncTask<String, String, String> {

                        /**
                         * Before starting background thread Show Progress Dialog
                         * */
                        @Override
                        protected void onPreExecute() {
                            super.onPreExecute();
                            pDialog = new ProgressDialog(AllProductsActivity.this);
                            pDialog.setMessage("Loading products. Please wait...");
                            pDialog.setIndeterminate(false);
                            pDialog.setCancelable(false);
                            pDialog.show();
                        }

                        /**
                         * getting All products from url
                         * */
                        protected String doInBackground(String... args) {
                            // Building Parameters
                            List<NameValuePair> params = new ArrayList<NameValuePair>();
                            // getting JSON string from URL
                            JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);

                            // Check your log cat for JSON reponse
                            Log.d("All Products: ", json.toString());

                            try {
                                // Checking for SUCCESS TAG
                                int success = json.getInt(TAG_SUCCESS);

                                if (success == 1) {
                                    // products found
                                    // Getting Array of Products
                                    products = json.getJSONArray(TAG_PRODUCTS);

                                    // looping through All Products
                                    for (int i = 0; i < products.length(); i++) {
                                        JSONObject c = products.getJSONObject(i);

                                        // Storing each json item in variable
                                        String id = c.getString(TAG_PID);
                                        String name = c.getString(TAG_NAME);

                                        // creating new HashMap
                                        HashMap<String, String> map = new HashMap<String, String>();

                                        // adding each child node to HashMap key => value
                                        map.put(TAG_PID, id);
                                        map.put(TAG_NAME, name);

                                        // adding HashList to ArrayList
                                        productsList.add(map);
                                    }
                                } else {
                                    // no products found
                                    // Launch Add New product Activity
                                    Intent i = new Intent(getApplicationContext(),
                                            NewProductActivity.class);
                                    // Closing all previous activities
                                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    startActivity(i);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                            return null;
                        }

                        /**
                         * After completing background task Dismiss the progress dialog
                         * **/
                        protected void onPostExecute(String file_url) {
                            // dismiss the dialog after getting all products
                            pDialog.dismiss();
                            // updating UI from Background Thread
                            runOnUiThread(new Runnable() {
                                public void run() {
                                    /**
                                     * Updating parsed JSON data into ListView
                                     * */
                                    ListAdapter adapter = new SimpleAdapter(
                                            AllProductsActivity.this, productsList,
                                            R.layout.list_item, new String[] { TAG_PID,
                                                    TAG_NAME},
                                            new int[] { R.id.pid, R.id.name });
                                    // updating listview
                                    setListAdapter(adapter);
                                }
                            });

                        }

                    }

                    }


                Here in this code , am trying to display three data , "name, price, description. The PHP file will 
                retrieve the data from the database mysql  , and convert the strings into JSon objects. Then my javacode will call the json class and list the data. I can successfully insert the data to the mysql.Am using PHP and JSON parsing for it.When the data inserted into database, the next activity should be listing the data.The problem is no data is coming into my listing activity. only the Activity is coming without data. kindly help me .


 My JSON class for parsing or converting is as follows

            This is my JSON parsing code .In this code first i created a function for get json from the url . then the code for making http request for GET and POST method by using if , else statement . In else method i put the code for get method . i converted it into json object , and the above android code will call it and display it in the activity..
        I used a JSON Parser class to get JSON from URL. This class supports two http request methods GET and POST to get json from url.
    As we are getting the JSON by making HTTP call, I am adding a Async method to make http calls on background thread. Add the follwing method in your main activity class

                public JSONParser() {

                    }

                    // function get json from url
                    // by making HTTP POST or GET mehtod
                    public JSONObject makeHttpRequest(String url, String method,
                            List<NameValuePair> params) {

                        // Making HTTP request
                        try {

                            // check for request method
                            if(method == "POST"){
                                // request method is POST
                                // 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();

                            }else if(method == "GET"){
                                // request method is GET
                                DefaultHttpClient httpClient = new DefaultHttpClient();
                                String paramString = URLEncodedUtils.format(params, "utf-8");
                                url += "?" + paramString;
                                HttpGet httpGet = new HttpGet(url);

                                HttpResponse httpResponse = httpClient.execute(httpGet);
                                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();
                        } catch (Exception e) {
                            Log.e("Buffer Error", "Error converting result " + e.toString());
                        }

                        // try parse the string to a JSON object
                        try {
                            jObj = new JSONObject(json);
                        } catch (JSONException e) {
                            Log.e("JSON Parser", "Error parsing data " + e.toString());
                        }

                        // return JSON String
                        return jObj;

                    }
                }    


            This is my JSON parsing code .In this code first i created a function for get json from the url . then the code for making http request for GET and POST method by using if , else statement . In else method i put the code for get method . i converted it into json object , and the above android code will call it and display it in the activity..
    I used a JSON Parser class to get JSON from URL. This class supports two http request methods GET and POST to get json from url.
As we are getting the JSON by making HTTP call, I am adding a Async method to make http calls on background thread. Add the follwing method in your main activity class

Thankyou
@ Manish Dubay
According to the instruction i got from you i changed the code in JSONObject.still nothing will be displayed on my Allproducts activity. Myt Logcat error when i add Log.v("json String","Result => "+json);

03-10 03:49:54.491: W/System.err(1559): org.json.JSONException: No value for products
03-10 03:49:54.491: W/System.err(1559):     at org.json.JSONObject.get(JSONObject.java:354)
03-10 03:49:54.508: I/Choreographer(1559): Skipped 97 frames!  The application may be doing too much work on its main thread.
03-10 03:49:54.528: W/System.err(1559):     at org.json.JSONObject.getJSONArray(JSONObject.java:548)
03-10 03:49:54.558: W/System.err(1559):     at com.example.sampleapp2.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:141)
03-10 03:49:54.618: W/System.err(1559):     at com.example.sampleapp2.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
03-10 03:49:54.668: W/System.err(1559):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-10 03:49:54.698: W/System.err(1559):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-10 03:49:54.718: W/System.err(1559):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-10 03:49:54.748: W/System.err(1559):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-10 03:49:54.788: W/System.err(1559):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-10 03:49:54.898: I/Choreographer(1559): Skipped 84 frames!  The application may be doing too much work on its main thread.
03-10 03:49:54.958: W/System.err(1559):     at java.lang.Thread.run(Thread.java:841)
03-10 03:49:55.038: I/Choreographer(1559): Skipped 83 frames!  The application may be doing too much work on its main thread.
03-10 03:49:55.168: I/Choreographer(1559): Skipped 212 frames!  The application may be doing too much work on its main thread.
03-10 03:49:55.218: I/Choreographer(1559): Skipped 55 frames!  The application may be doing too much work on its main thread.

解决方案

Error parsing data org.json.JSONException: Value get_all_products.php of type java.lang.String cannot be converted to JSONObject

states that you don't have valid json string in your resopnse coming from web service. Becuase of this jObj = isValidJson(json); doesn't return any json object.

In your above code, at

json = sb.toString();

You are creating String named as json and assign string builder object value to it. But you logcat says that you are not geeting valid json string at below line,

try {
                        jObj = new JSONObject(json);
                    } catch (JSONException e) {
                        Log.e("JSON Parser", "Error parsing data " + e.toString());
                    }

So it throws error about parsing json string. In this case you have to check whether you go t valid json string from server in response. Make some changes in above code:

public boolean isValidJson(String test)
{
    try {
        new JSONObject(test);
        return true;
    } catch(JSONException ex) { 
        return false;
    }
}

And, in your code:

try {
       if(isValidJson(json)
    {
      jObj = new JSONObject(json);
    } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
    } 

这篇关于无法在我从MySQL的Andr​​oid应用程序列表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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