android - json show permission error help please -


this code (below), give error on log

"java.lang.runtimeexception: unable open trace file '/sdcard/jsonobject.trace': permission denied"

the first json works fine . second jsonarray dataarray = data.getjsonobject("observations").getjsonarray( json parsing causing problem, do? me please.

 public class fifthstep extends activity { // imagebutton imgnews, imgcontact, imgsetting; // listview listmainmenu;  // mainmenuadapter mma; private horizontallistview listview; //private horizontalview listview;  categorylistadapter2 cla;  static arraylist<long> category_id = new arraylist<long>(); static arraylist<string> category_name = new arraylist<string>(); static arraylist<string> category_image = new arraylist<string>();    string categoryapi;    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.mainmenulist);     // imgnews = (imagebutton) findviewbyid(r.id.imgnews);     // imgcontact = (imagebutton) findviewbyid(r.id.imgcontact);       listview = (horizontallistview) this.findviewbyid(r.id.listview);      cla = new categorylistadapter2(fifthstep.this);    //  listview.setadapter(madapter);     categoryapi = utils.categoryapi;    //    cleardata();     try {          httpclient client = new defaulthttpclient();         httpconnectionparams.setconnectiontimeout(client.getparams(),       15000);         httpconnectionparams.setsotimeout(client.getparams(), 15000);         httpurirequest request = new httpget(categoryapi);         httpresponse response = client.execute(request);         inputstream atominputstream = response.getentity().getcontent();         bufferedreader in = new bufferedreader(new          inputstreamreader(atominputstream));          string line;         string str = "";         while ((line = in.readline()) != null){             str += line;         }               jsonobject json = new jsonobject(str);             jsonarray data = json.getjsonarray("worldpopulation");              (int = 0; < data.length(); i++) {                 jsonobject object = data.getjsonobject(i);               //    jsonobject category =                object.getjsonobject("category");            category_id.add(long.parselong(object.getstring("rank")));                 category_name.add(object.getstring("name"));                 category_image.add(object.getstring("url"));                  log.d("category name", category_name.get(i));                 listview.setadapter(cla);               }       } catch (malformedurlexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (ioexception e) {         // todo auto-generated catch block     //  ioconnect = 1;         e.printstacktrace();     } catch (jsonexception e) {         // todo auto-generated catch block         e.printstacktrace();     }                            }              @override protected void onstart() {     super.onstart();      // downloading rss feed needs done on separate thread.     thread downloadthread = new thread(new runnable() {          public void run() {             debug.startmethodtracing("jsonobject");             try {                 loaddata();             } catch (exception e) {                 log.e("content retriever",            e.getlocalizedmessage(), e);             } {                 debug.stopmethodtracing();             }         }     }, "reading thread");      downloadthread.start(); }  /**  * loads sample json data table.  *   * @throws jsonexception  * @throws ioexception  */ private void loaddata() throws jsonexception, ioexception {     populatetable(getcontent()); }  /**  * reads data {@link jsonobject}.  *   * @return data {@link jsonobject}  * @throws ioexception  * @throws jsonexception  */ private jsonobject getcontent() throws ioexception, jsonexception {     bufferedreader bufferedreader = null;     try {         inputstream instream = getresources().openrawresource(r.raw.json);          bufferedinputstream bufferedstream = new bufferedinputstream(                 instream);         inputstreamreader reader = new inputstreamreader(bufferedstream);         bufferedreader = new bufferedreader(reader);         stringbuilder builder = new stringbuilder();         string line = bufferedreader.readline();         while (line != null) {             builder.append(line);             line = bufferedreader.readline();         }          return new jsonobject(builder.tostring());     } {         if (bufferedreader != null) {             bufferedreader.close();         }     } }  /**  * populates table in main view data.  *   * @param data  *            read json data  * @throws jsonexception  */ private void populatetable(jsonobject data) throws jsonexception {     jsonarray dataarray = data.getjsonobject("observations").getjsonarray(             "data");     final tablelayout table = (tablelayout) findviewbyid(r.id.table);     (int = 0; < dataarray.length(); i++) {         final view row = createrow(dataarray.getjsonobject(i));         table.post(new runnable() {              public void run() {                 table.addview(row);             }         });     } }  /**  * creates row table based on observation.  *   * @param item  *            json object containing observation  * @return created row  * @throws jsonexception  */ private view createrow(jsonobject item) throws jsonexception {     view row = getlayoutinflater().inflate(r.layout.rows, null);     ((textview) row.findviewbyid(r.id.localtime)).settext(item             .getstring("local_date_time_full"));     ((textview) row.findviewbyid(r.id.apprenttemp)).settext(item             .getstring("apparent_t"));      return row; }   }                         <?xml version="1.0" encoding="utf-8"?>      <tablerow xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent" >   <textview     android:id="@+id/localtime"      android:textcolor="#ffffff"     android:gravity="left" />   <textview     android:id="@+id/apprenttemp"      android:textcolor="#ffffff"     android:gravity="center" />      </tablerow> 

you should request permission access sd card:

read_external_storage 

but should not needed. have checked if path correct?

furthermore see try read json file raw storage: r.raw.json not on sd card.


Comments