java - Error converting result HttpPost android -


i've been working on app pulls json string server. access json need post key , secret. else error saying key and/or secret missing.

my jsonfunctions.java

package com.spxc.ssa.streaming.task;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.util.arraylist; import java.util.hashmap; import java.util.list;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.httpclient; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.entity.stringentity; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;  import android.util.log;  public class jsonfunctions {      public static jsonobject getjsonfromurl(string url){         inputstream = null;         string result = "";         jsonobject jarray = null;          //http post         try{              httpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost(url);              try {                 // add data                 list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2);                 namevaluepairs.add(new basicnamevaluepair("key", "12345"));                 namevaluepairs.add(new basicnamevaluepair("secret", "anddev cool!"));                 httppost.setentity(new urlencodedformentity(namevaluepairs));                  // execute http post request                 httpresponse response = httpclient.execute(httppost);              } catch (clientprotocolexception e) {                 // todo auto-generated catch block             } catch (ioexception e) {                 // todo auto-generated catch block             }                   //mhfgpammv9f94ddayh8gsweji          }catch(exception e){                 log.e("log_tag", "error in http connection "+e.tostring());         }        //convert response string         try{                 bufferedreader reader = new bufferedreader(new inputstreamreader(is,"iso-8859-1"),8);                 stringbuilder sb = new stringbuilder();                 string line = null;                 while ((line = reader.readline()) != null) {                         sb.append(line + "\n");                 }                 is.close();                 result=sb.tostring();         }catch(exception e){                 log.e("log_tag", "error converting result "+e.tostring());         }          try{              jarray = new jsonobject(result);                     }catch(jsonexception e){                 log.e("log_tag", "error parsing data "+e.tostring());         }          return jarray;     } } 

my activity:

package com.spxc.ssa.streaming;  import java.util.arraylist; import java.util.hashmap;  import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;  import android.app.progressdialog; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter;  import com.actionbarsherlock.app.sherlocklistactivity; import com.actionbarsherlock.view.menuitem; import com.spxc.ssa.streaming.task.jsonasync; import com.spxc.ssa.streaming.task.jsonasync.jsonlistener;  public class listmoviescontroller extends sherlocklistactivity implements         onclicklistener {      private progressdialog mdialog;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         // getwindow().setformat(pixelformat.translucent);         setcontentview(r.layout.dblist);         getsupportactionbar().setdisplayhomeasupenabled(true);         getsupportactionbar().settitle("movies");          jsonasync asynctask = new jsonasync();         // using anonymous interface listen objects when task         // completes.         asynctask.setjsonlistener(new jsonlistener() {             @override             public void onobjectreturn(jsonobject object) {                 handlejsonobject(object);             }         });         // show progress loader while accessing network, , start async task.         mdialog = progressdialog.show(this, getsupportactionbar().gettitle(),                 getstring(r.string.loading), true);         asynctask.execute("http://sirsmokealot.ch/api/video/movies/");      }      @override     public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {         case android.r.id.home:             finish();             break;         }         return false;     }      @override     public void onclick(view v) {         // todo auto-generated method stub      }      private void handlejsonobject(jsonobject object) {         arraylist<hashmap<string, string>> mylist = new arraylist<hashmap<string, string>>();          try {              jsonarray shows = object.getjsonarray("items");              (int = 0; < shows.length(); i++) {                 hashmap<string, string> map = new hashmap<string, string>();                 jsonobject e = shows.getjsonobject(i);                  map.put("video_id", string.valueof(i));                 map.put("video_title", "" + e.getstring("video_title"));                 map.put("video_channel", "" + e.getstring("video_channel"));                 map.put("video_location", "" + e.getstring("video_location"));                 mylist.add(map);             }         } catch (jsonexception e) {             log.e("log_tag", "error parsing data " + e.tostring());         }          listadapter adapter = new simpleadapter(this, mylist, r.layout.dbitems,                 new string[] { "video_title", "video_location" }, new int[] { r.id.item_title,                         r.id.item_subtitle });          setlistadapter(adapter);          final listview lv = getlistview();         lv.settextfilterenabled(true);         lv.setonitemclicklistener(new onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) {                 @suppresswarnings("unchecked")                 hashmap<string, string> o = (hashmap<string, string>) lv                         .getitematposition(position);                  intent myintent = new intent(listmoviescontroller.this,                         testvideocontroller.class);                 myintent.putextra("video_title", o.get("video_title"));                 myintent.putextra("video_channel", o.get("video_channel"));                 myintent.putextra("video_location", o.get("video_location"));                 startactivity(myintent);             }         });          if (mdialog != null && mdialog.isshowing()) {             mdialog.dismiss();         }     }  } 

my logcat says:

error converting result java.lang.nullpointerexception: lock == null error parsing data org.json.jsonexception: end of input @ character 0 of  

any appreciated! thanks

you miss these 2 lines after getting response server

// execute http post request

 httpresponse response = httpclient.execute(httppost);  httpentity httpentity = httpresponse.getentity();  = httpentity.getcontent(); 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -