error ocuring while connecting to android and php with mysql -


i have following code in post_item.java file:

package com.iwantnew.www;  import java.util.arraylist; import java.util.list;  import org.apache.http.namevaluepair; import org.apache.http.message.basicnamevaluepair; import org.json.jsonexception; import org.json.jsonobject;  import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import android.widget.edittext;  public class post_item extends activity {     private progressdialog pdialog;     jsonparser jsonparser = new jsonparser();     button add_room;     edittext contact_no;     edittext no_of_room;     edittext price_per_room;     edittext description;      private static string url_create_product = "http://10.0.2.2/android_iwant/android_add_room.php";      private static final string tag_success = "success";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.post_form);          //contact_no = (edittext) findviewbyid(r.id.contact_no);         no_of_room = (edittext) findviewbyid(r.id.no_of_room);         price_per_room = (edittext) findviewbyid(r.id.price_per_room);         //description = (edittext) findviewbyid(r.id.description);         contact_no = (edittext) findviewbyid(r.id.contact_no);          add_room = (button) findviewbyid(r.id.add_room);          add_room.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // creating new product in background thread                 new add_new_room().execute();             }         });     } // suru...     class add_new_room extends asynctask<string, string, string> {          /**          * before starting background thread show progress dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(post_item.this);             pdialog.setmessage("saving details..");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }          /**          * creating product          * */         protected string doinbackground(string... args) {             //string contact = contact_no.gettext().tostring();             string quantity = no_of_room.gettext().tostring();             string price = price_per_room.gettext().tostring();             //string contact = contact_no.gettext().tostring();             string descriptions = description.gettext().tostring();              // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();             //params.add(new basicnamevaluepair("contact", contact));             params.add(new basicnamevaluepair("quantity", quantity));             params.add(new basicnamevaluepair("price", price));             params.add(new basicnamevaluepair("descriptions", descriptions));              // getting json object             // note create product url accepts post method             jsonobject json = jsonparser.makehttprequest(url_create_product,                     "post", params);              // check log cat fro response              log.d("create response", json.tostring());              // check success tag             try {                 int success = json.getint(tag_success);                  if (success == 1) {                     // created product                     intent = new intent(getapplicationcontext(), mainactivity.class);                     startactivity(i);                      // closing screen                     finish();                 } else {                     // failed create product                 }             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }          /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog once done             pdialog.dismiss();         }      } } 

and, have following in php file:

<?php  /* * following code create new product row * product details read http post request */  // array json response $response = array();  // check required fields  if (isset($_post['quantity']) &&  isset($_post['price'])) {      //$location = $_post['location'];     $quantity = $_post['quantity'];     $price = $_post['price'];     //$productid = $_post['area'];     //$contact = $_post['contact'];     $descriptions = $_post['descriptions'];      // include db connect class    require_once __dir__ . '/db_connect.php';      // connecting db     $db = new db_connect();      // mysql inserting new row       $result = mysql_query("insert room_tb(uid,categoryid,quantity,price,description) values(5,1,'$quantity','$price','$descriptions')");     //$result1 = mysql_query("insert users(usercontactnumber) values('$contact')");      // check if row inserted or not     if($result)/*&& ($result1)*/ {         // inserted database         $response["success"] = 1;         $response["message"] = "room added successfully.";          // echoing json response         echo json_encode($response);     } else {         // failed insert row         $response["success"] = 0;         $response["message"] = "oops! error occurred.";          // echoing json response         echo json_encode($response);     } } else {     // required field missing     $response["success"] = 0;     $response["message"] = "required field(s) missing";      // echoing json response     echo json_encode($response); } ?> 

whenever send description or contact number database, android emulator says "unexpectedly stopped working", , no records enter database. but, if pass quantity, price, categoryid, , uid, no error occurs , record goes database. doing wrong?

here link log cat http://pastebin.com/wvbps2gs

caused by: java.lang.nullpointerexception 07-15 02:06:36.366: e/androidruntime(2918):     @    com.iwantnew.www.post_item$add_new_room.doinbackground(post_item.java:96) 

so whatever on line 96, it's null , should checked for. there no line numbers in codesnippet think has use of descriptions variable:

string descriptions = description.gettext().tostring(); 

while assignment variable description set in comments

//description = (edittext) findviewbyid(r.id.description); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -