• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps problem with insertion the data from my android app

camabir

Lurker
Sep 21, 2015
1
0
hello Every body, it's the first time that i try to developp an android application my problem is that when i insert the data on a form and i click on the "save" button its this product an error IOException to which i have not found a solution , here is the code of the button click.

buttonEnregistrer.setOnClickListener(new View.OnClickListener(){
InputStream is =null;
@override
public void onClick(View v) {
// TODO Auto-generated method stub
//storing the values into the editexts inside the string variables
String NumFom = ""+EditNumFom.getText().toString();
String Projet = ""+editProjet.getText().toString();
String NumAffaire = ""+editNumAff.getText().toString();
//setting the name Values Pairs
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
//adding the string variables inside the nameValuePair
nameValuePairs.add(new BasicNameValuePair("NumFom", NumFom));
nameValuePairs.add(new BasicNameValuePair("Projet", Projet));
nameValuePairs.add(new BasicNameValuePair("NumAffaire", NumAffaire));
//setting up the connection into the try catch blocks
try{//setting up the default httpClient
HttpClient httpClient = new DefaultHttpClient();

//setting up the http post method and passing the url in case
//of online database and the ip address in case of localhost database
// and the php files which serves as the link between the android app
// and the database
HttpPost httpPost = new HttpPost("http://10.0.2.2/sdel2/connection.php");

// passing the nameValuePair inside the httpPost
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// getting the response
HttpResponse response = httpClient.execute(httpPost);

//setting up the entity
HttpEntity entity = response.getEntity();

// setting up the content inside an input stream reader
// let's define the input stream Reader
is = entity.getContent();
//displaying the toast message if the entered successfully
String msg = "Data entered successfully";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}// writing the catch block to handle the exceptions

catch (ClientProtocolException e){

Log.e("ClientProtocol", "Log_Tag");
e.printStackTrace();
}catch(IOException e){
Log.e("Log_Tag", "IOException");
e.printStackTrace();


}





}

});


and thanks for your help

 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones