android - App crashes while displaying location from mysql -


my app supposed retrieve marker's longitude , latitude database (in case mysql) , display them on map. works before tried retrieve data web. can me? other codes here

route_activity.java

package com.example.wibisono.tryhard_1;  import android.location.criteria; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.os.asynctask; import android.os.bundle; import android.support.v4.app.fragmentactivity;  import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.googleplayservicesutil; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions;  import org.json.jsonexception; import org.json.jsonobject;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.net.httpurlconnection; import java.net.malformedurlexception; import java.net.url; import java.util.hashmap; import java.util.list;  public class route_activity extends fragmentactivity implements locationlistener {      googlemap googlemap;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         //show error dialog if goolgleplayservices not available         if (!isgoogleplayservicesavailable()) {             finish();         }         setcontentview(r.layout.map_route);         supportmapfragment supportmapfragment =                 (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map);         googlemap = supportmapfragment.getmap();         googlemap.setmylocationenabled(true);         locationmanager locationmanager = (locationmanager) getsystemservice(location_service);         criteria criteria = new criteria();         string bestprovider = locationmanager.getbestprovider(criteria, true);         location location = locationmanager.getlastknownlocation(bestprovider);         if (location != null) {             onlocationchanged(location);         }         locationmanager.requestlocationupdates(bestprovider, 20000, 0, this);          new retrievetask().execute();     }      // adding marker on googlemaps     //private void addmarker(latlng latlng) {       //  markeroptions markeroptions = new markeroptions();        // markeroptions.position(latlng);        // markeroptions.title(latlng.latitude + "," + latlng.longitude);        // googlemap.addmarker(markeroptions);     //}      // background task retrieve locations remote mysql server     private class retrievetask extends asynctask<void, void, string> {          @override         protected string doinbackground(void... params) {             string strurl = "http://nfcworld.web.id/public_html/wibisono/retrieve.php";             url url = null;             stringbuffer sb = new stringbuffer();             try {                 url = new url(strurl);                 httpurlconnection connection = (httpurlconnection) url.openconnection();                 connection.connect();                 inputstream istream = connection.getinputstream();                 bufferedreader reader = new bufferedreader(new inputstreamreader(istream));                 string line = "";                 while( (line = reader.readline()) != null){                     sb.append(line);                 }                  reader.close();                 istream.close();              } catch (malformedurlexception e) {                 e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             }             return sb.tostring();         }          @override         protected void onpostexecute(string result) {             super.onpostexecute(result);             new parsertask().execute(result);         }     }      // background thread parse json data retrieved mysql server     private class parsertask extends asynctask<string, void, list<hashmap<string, string>>>{         @override         protected list<hashmap<string,string>> doinbackground(string... params) {             directionsjsonparser markerparser = new directionsjsonparser();             jsonobject json = null;             try {                 json = new jsonobject(params[0]);             } catch (jsonexception e) {                 e.printstacktrace();             }             list<hashmap<string, string>> markerslist = markerparser.parse(json);             return markerslist;         }         @override         protected void onpostexecute(list<hashmap<string, string>> result) {             for(int i=0; i<result.size();i++){                 hashmap<string, string> marker = result.get(i);                 latlng latlng = new latlng(double.parsedouble(marker.get("lat")), double.parsedouble(marker.get("lng")));                 //addmarker(latlng);             }         }     }      @override     public void onlocationchanged(location location) {         //textview locationtv = (textview) findviewbyid(r.id.latlonglocation);         double latitude = location.getlatitude();         double longitude = location.getlongitude();         latlng latlng = new latlng(latitude, longitude);         //googlemap.addmarker(new markeroptions().position(latlng));         googlemap.movecamera(cameraupdatefactory.newlatlng(latlng));         googlemap.animatecamera(cameraupdatefactory.zoomto(16));         //locationtv.settext("latitude:" + latitude + ", longitude:" + longitude);     }      @override     public void onproviderdisabled(string provider) {         // todo auto-generated method stub     }      @override     public void onproviderenabled(string provider) {         // todo auto-generated method stub     }      @override     public void onstatuschanged(string provider, int status, bundle extras) {         // todo auto-generated method stub     }      private boolean isgoogleplayservicesavailable() {         int status = googleplayservicesutil.isgoogleplayservicesavailable(this);         if (connectionresult.success == status) {             return true;         } else {             googleplayservicesutil.geterrordialog(status, this, 0).show();             return false;         }     }  } 

and these errors got

11-11 00:29:55.443 2008-2482/com.example.wibisono.tryhard_1 e/androidruntime: fatal exception: asynctask #2                                                                               process: com.example.wibisono.tryhard_1, pid: 2008                                                                               java.lang.runtimeexception: error occured while executing doinbackground()                                                                                   @ android.os.asynctask$3.done(asynctask.java:304)                                                                                   @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355)                                                                                   @ java.util.concurrent.futuretask.setexception(futuretask.java:222)                                                                                   @ java.util.concurrent.futuretask.run(futuretask.java:242)                                                                                   @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231)                                                                                   @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112)                                                                                   @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587)                                                                                   @ java.lang.thread.run(thread.java:818)                                                                                caused by: java.lang.nullpointerexception: attempt invoke virtual method 'org.json.jsonarray org.json.jsonobject.getjsonarray(java.lang.string)' on null object reference                                                                                   @ com.example.wibisono.tryhard_1.directionsjsonparser.parse(directionsjsonparser.java:23)                                                                                   @ com.example.wibisono.tryhard_1.route_activity$parsertask.doinbackground(route_activity.java:116)                                                                                   @ com.example.wibisono.tryhard_1.route_activity$parsertask.doinbackground(route_activity.java:106)                                                                                   @ android.os.asynctask$2.call(asynctask.java:292)                                                                                   @ java.util.concurrent.futuretask.run(futuretask.java:237)                                                                                   @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231)                                                                                    @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112)                                                                                    @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587)                                                                                    @ java.lang.thread.run(thread.java:818)  


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -