Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:MySQL数据传递失败_Android_Mysql - Fatal编程技术网

Android:MySQL数据传递失败

Android:MySQL数据传递失败,android,mysql,Android,Mysql,我试图从mysql数据库中获取一些数据,并在文本视图中打印它们。 我正在使用一个查询,该查询使用我的应用程序通过POST传递的数据识别行 这就是.java: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calendario); Stric

我试图从mysql数据库中获取一些数据,并在文本视图中打印它们。 我正在使用一个查询,该查询使用我的应用程序通过POST传递的数据识别行

这就是.java:

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

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    app_preferences = PreferenceManager.getDefaultSharedPreferences(this);

    LoginClass ID_P =  ((LoginClass)getApplicationContext());
    id_user = ID_P.getID();
    Log.d("id_w?",id_user);


    text = (TextView) findViewById(R.id.text_pren);
    fill_text();

}

private void fill_text(){

    try{
        httpclient = new DefaultHttpClient();
        httppost = new HttpPost("******MY URI*******");
        response = httpclient.execute(httppost);
        prenotazione = new ArrayList<NameValuePair>(1);
        prenotazione.add(new BasicNameValuePair("id_user",id_user));
        httppost.setEntity(new UrlEncodedFormEntity(prenotazione));
        Log.d("gladdi",prenotazione.toString());
        HttpEntity entity = response.getEntity();
        inputStream = entity.getContent();


        } 
        catch (Exception e){
            Toast.makeText(CalendarioActivity.this, "error"+e.toString(), Toast.LENGTH_LONG).show();
        }
            if(inputStream != null){
            Log.d("glad2",id_user);
            try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                inputStream.close();
                result = sb.toString();

                Log.d("sort",result);
            }catch(Exception e){
                Log.e("TEST", "Errore nel convertire il risultato "+e.toString());
                }
        try{
            JSONArray jArray = new JSONArray(result);
            prenotazioni = "";
            for(int i=0;i<jArray.length();i++){
                JSONObject json_pren = jArray.getJSONObject(i);
                result_string = "Prenotazione in data "+json_pren.getString("data")+", "+json_pren.getString("dettagli")+"\n\n";
                prenotazioni = prenotazioni + result_string;
                }
            }catch(JSONException e){
                Log.e("log_tag", "Error parsing data "+e.toString());
                    }   
        }else{
            //do nothing
        }

            text.setText(prenotazioni);
}//end fill_text()
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u calendario);
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
app_preferences=PreferenceManager.getDefaultSharedReferences(此选项);
LoginClass ID_P=((LoginClass)getApplicationContext());
id_user=id_P.getID();
Log.d(“id\u w?”,id\u用户);
text=(TextView)findViewById(R.id.text\u pren);
填充文本();
}
专用空白填充_text(){
试一试{
httpclient=新的DefaultHttpClient();
httppost=新的httppost(“*******我的URI*******”);
response=httpclient.execute(httppost);
prenotazione=新阵列列表(1);
添加(新的BasicNameValuePair(“id_用户”,id_用户));
setEntity(新的UrlEncodedFormEntity(prenotazione));
Log.d(“gladdi”,prenotazione.toString());
HttpEntity=response.getEntity();
inputStream=entity.getContent();
} 
捕获(例外e){
Toast.makeText(CalendarioActivity.this,“error”+e.toString(),Toast.LENGTH\u LONG.show();
}
如果(inputStream!=null){
Log.d(“glad2”,id_用户);
试一试{
BufferedReader=新的BufferedReader(新的InputStreamReader(inputStream,“iso-8859-1”),8);
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
inputStream.close();
结果=sb.toString();
Log.d(“排序”,结果);
}捕获(例外e){
Log.e(“测试”、“错误”转换为“错误”+e.toString());
}
试一试{
JSONArray jArray=新JSONArray(结果);
prenotazioni=“”;
对于(int i=0;i_GET),但不是在启动应用程序时…就像字符串“id_user”没有传递一样。。。

我希望我说的很清楚。你能帮我吗?

我肯定这只是一个疏忽,但在你得到结果之前发送参数会有帮助

更改此项:

    response = httpclient.execute(httppost);
    prenotazione = new ArrayList<NameValuePair>(1);
    prenotazione.add(new BasicNameValuePair("id_user",id_user));
    httppost.setEntity(new UrlEncodedFormEntity(prenotazione));
response=httpclient.execute(httppost);
prenotazione=新阵列列表(1);
添加(新的BasicNameValuePair(“id_用户”,id_用户));
setEntity(新的UrlEncodedFormEntity(prenotazione));
为此:

    prenotazione = new ArrayList<NameValuePair>(1);
    prenotazione.add(new BasicNameValuePair("id_user",id_user));
    httppost.setEntity(new UrlEncodedFormEntity(prenotazione));
    response = httpclient.execute(httppost);
prenotazione=新阵列列表(1);
添加(新的BasicNameValuePair(“id_用户”,id_用户));
setEntity(新的UrlEncodedFormEntity(prenotazione));
response=httpclient.execute(httppost);