问题N Convert NullPointerException Android Studio Para Rutas Con MySQL

时间:2019-05-12 21:43:09

标签: android

受宠,他成功地将自己的隐私权归因于NullPointerException

请帮忙,我已经按照指南从数据库中提取点进行跟踪,但是我遇到了NullPointerException问题

enter image description here

一个连续的les mando elcódigo

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback,
        GoogleMap.OnPolylineClickListener, GoogleMap.OnPolygonClickListener {
    private GoogleMap googleMap;
    private ArrayList<LatLng> arrayPoints = null;
    PolylineOptions polylineOptions;

    HttpResponse httpResponse;
    JSONObject jsonObject = null ;
    String StringHolder = "" ;
    String HttpURL = "https://boskier-patches.000webhostapp.com/polyline.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new ObtenerDatos(MainActivity.this).execute();
        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        fm.getMapAsync(this);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            return;
        }

    }

    public class ObtenerDatos extends AsyncTask<Void, Void, Void>
    {
        public Context context;


        public ObtenerDatos(Context context)
        {
            this.context = context;
        }

        @Override
        protected void onPreExecute()
        {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... arg0)
        {

            HttpClient httpClient = new DefaultHttpClient();

            // Adding HttpURL to my HttpPost oject.
            HttpPost httpPost = new HttpPost(HttpURL);

            try {
                httpResponse = httpClient.execute(httpPost);

                StringHolder = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try{
                // Passing string holder variable to JSONArray.
                JSONArray jsonArray = new JSONArray(StringHolder);
                jsonObject = jsonArray.getJSONObject(0);


            } catch ( JSONException e) {
                e.printStackTrace();
            }

            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(Void result)
        {

        }
    }
    public void onMapReady(GoogleMap googleMap) {
        try {
            String latitude1 = jsonObject.getString("lat1");
            String longitude1 = jsonObject.getString("lon1");
            String latitude2 = jsonObject.getString("lat2");
            String longitude2 = jsonObject.getString("lon2");
            String latitude3 = jsonObject.getString("lat3");
            String longitude3 = jsonObject.getString("lon3");
            double lat1 = Double.parseDouble(String.valueOf(latitude1));
            double lon1 = Double.parseDouble(String.valueOf(longitude1));
            double lat2 = Double.parseDouble(String.valueOf(latitude2));
            double lon2= Double.parseDouble(String.valueOf(longitude2));
            double lat3 = Double.parseDouble(String.valueOf(latitude3));
            double lon3= Double.parseDouble(String.valueOf(longitude3));

            arrayPoints = new ArrayList<>();
            arrayPoints.add(new LatLng(lat1, lon1));
            arrayPoints.add(new LatLng(lat2, lon2));
            arrayPoints.add(new LatLng(lat3, lon3));


            for(int aind = 0 ; aind < arrayPoints.size(); aind++){

                //agregamos los marker
                googleMap.addMarker(new MarkerOptions()
                        .position(arrayPoints.get(aind))
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
            }
            polylineOptions = new PolylineOptions();
            polylineOptions.color(Color.RED);
            polylineOptions.width(5);
            polylineOptions.addAll(arrayPoints);
            googleMap.addPolyline(polylineOptions);


            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(arrayPoints.get(2), 13));


        googleMap.setOnPolylineClickListener(this);
        googleMap.setOnPolygonClickListener(this);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public void onPolygonClick(Polygon polygon) {

    }
    @Override
    public void onPolylineClick(Polyline polyline) {

    }
}

0 个答案:

没有答案