dqzg62440 2019-06-20 08:41
浏览 50

手机准备连接mysql意外退出

I have use mysql for a while, and there is no problem with the connection between computers.

I’m practicing Android Studio recently.

Reference URL:https://www.youtube.com/watch?v=EZshEey2feg

I am executing on Android Studio, quite perfect, without any errors

But I packaged it into an .apk installation, execute

Immediately unexpected quit, no warning

I found that when reading mysql data, it will unexpectedly quit

My code

[MainActivity.java]

private Runnable runTimerStop = new Runnable() {
        @Override
        public void run() {
            select(null);
        }
    };

public void select(String id) {
        try {
            String r = DBphp.DBstring(id,cookieStr,url);
            JSONArray jsonArray = new JSONArray(r);
            List<Map<String,Object>> items = new ArrayList<Map<String, Object>>();

            for (int i = 0 ; i < jsonArray.length() ; i++){
                JSONObject jsonData = jsonArray.getJSONObject(i);
                Map<String,Object> item = new HashMap<String,Object>();
                item.put("ID",jsonData.getString("ID"));
                item.put("Name",jsonData.getString("Name"));
                item.put("m1",jsonData.getString("m1"));
                item.put("m2",jsonData.getString("m2"));
                item.put("m3",jsonData.getString("m3"));
                items.add(item);
                }
            SimpleAdapter SA = new SimpleAdapter(context,items,R.layout.list_text, new String[]{"ID", "Name", "m1", "m2", "m3"}, new int[]{R.id.text0, R.id.text1, R.id.text2, R.id.text3, R.id.text4});
            LV1.setAdapter(SA);
        } catch (Exception e) {
            Log.e("log_tag", e.toString());
        }
    }

[DBphp.java]

public class DBphp {
    private static HttpClient hC;
    private static HttpPost hP;
            public  static  String DBstring(String i, String Wcook, String url){
                String result="Error";
                try{
                    hC = new DefaultHttpClient();
                    hP = new HttpPost(url+"/index.php");
                    hP.addHeader("Cookie",Wcook+";expires=thu,31-Dec-37 23:55:55 GMT; path=/");
                    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("S1",i));
                    hP.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

                    HttpResponse hR = hC.execute(hP);
                    HttpEntity hE = hR.getEntity();
                    InputStream inputStream = hE.getContent();
                    BufferedReader bufReader = new BufferedReader(new InputStreamReader(inputStream, HTTP.UTF_8),8);
                    StringBuilder builder = new StringBuilder();
                    String line=null;
                    while ((line = bufReader.readLine()) != null){
                        builder.append(line+"
");
                    }
                    inputStream.close();
                    result = builder.toString();

        }catch (Exception e){
            result=e.toString();
        }finally {
            hC.getConnectionManager().shutdown();
        }
        return  result;
    }
}

[SQL_data.php]

<?PHP
$hostname = "192.168.1.240";
$username = "AppUser";
$password = "root";
$database = "text";

$GD = mysqli_connect($hostname, $username, $password) or trigger_error(mysqli_error(), E_USER_ERROR);

//UTF8
mysqli_query($GD, "SET NAMES UTF8");
mysqli_query($GD, "SET CHARACTER_SET_CLIENT='utf8'");
mysqli_query($GD, "SET CHARACTER_SET_RESULTS='utf8'");
?>

[index.php]

<?php
require_once("SQL_data.php");

$sql="SELECT * FROM `text1` ORDER BY `ID`DESC;";
mysqli_select_db($GD,$database);
$Result=mysqli_query($GD,$sql) or die(mysqli_error($GD));

while($r = mysqli_fetch_assoc($Result))
$output[]=$r;
header('Content-type: application/json; charset=utf-8');

print(json_encode($output,JSON_UNESCAPED_UNICODE));
exit();
mysql_close();
?>

Why is this happening? Please help me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line