首页 > 解决方案 > Android 模拟器应用程序无法连接到我的本地 mysql 服务器

问题描述

    // URL
    private final static String base_URL = "http://10.0.2.2:8080/shreemant/fetch_product.php";
    RequestQueue queue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.delivery);

        final TextView txtName = (TextView)findViewById(R.id.txtName);
        final TextView txtAddress = (TextView)findViewById(R.id.txtAddress);

        queue = Volley.newRequestQueue(this);
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, base_URL, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            txtName.setText(response.getString("NAME"));
                            txtAddress.setText(response.getString("ADDRESS"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("error", error.toString());
            }
        });
        queue.add(request);

在 safari 中键入相同的 URL 会显示JSON我的php脚本所回显的结构。无法弄清楚为什么它不能在 Android Studio 上运行。方法也试过了Gson,得到了error parsing TSL header。错误 非常感谢任何帮助。

这是 Web 浏览器中的输出:

{"ORDER_NO":"1","NAME":"PRITESH GOYAL","PHONE":"9893291225","ADDRESS":"CHOTI GWALTOLI","ORDER_DESC":"COW GHEE - 1 KG - QT -1","AMOUNT":"500","DRIVER":"VINOD","LANDMARK":"PATEL BRIDGE"}

标签: phpandroidjsongsonandroid-volley

解决方案


推荐阅读