StartActivityForResult空字符串有问题

时间:2020-05-19 08:17:55

标签: startactivityforresult

我对startActivityForResult有问题。我正在尝试使用http get将MainActivity的意图发送给Centroid.activity,以进行质心计算。来自Centroid.activity的日志很好,但是在MainActivity中显示为nullException。

dir /x

这是我的onActivityResult。我不知道怎么了。

cal_centroid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter1.items.size() == 0)
                    Toast.makeText(getApplicationContext(),"insert origin",Toast.LENGTH_SHORT).show();
                else{
                    Intent intent = new Intent(MainActivity.this, Centroid.class);
                    intent.putExtra("locations", adapter1.items);
                    startActivityForResult(intent,REQUEST_CODE);


                    Log.d(TAG, "centroid: "+centroid);
                    double centroid_latitude;
                    double centroid_longitude;

                    centroid = centroid.substring(1,centroid.length()-2);
                    int comma = centroid.indexOf(',');
                    centroid_latitude = Double.parseDouble(centroid.substring(0,comma-1));
                    centroid_longitude = Double.parseDouble(centroid.substring(comma+2,centroid.length()));

                    if (currentMarker != null) {
                        currentMarker.remove();
                        currentMarker = null;
                    }
                    for (int i=0; i<adapter1.items.size(); i++){
                        MarkerOptions markerOptions = new MarkerOptions();
                        markerOptions
                                .position(new LatLng(adapter1.items.get(i).latitude, adapter1.items.get(i).longitude))
                                .title(adapter1.items.get(i).name);
                        map.addMarker(markerOptions);
                    }
                    MarkerOptions markerOptions = new MarkerOptions();
                    markerOptions.position(new LatLng(centroid_latitude,centroid_longitude))
                            .title("Centroid");
                    map.addMarker(markerOptions);




            }}
        });

为什么String getcentroid获得空字符串?我没有线索。请帮忙:)

0 个答案:

没有答案