在Android中,我正在尝试从URL获取数据以在地图上绘图,但我遇到问题甚至打印它

时间:2017-08-29 07:25:33

标签: android request google-maps-android-api-2

我正在尝试从在线获取一些数据,这是CSV格式,但是,我在日志cat监视器中收到了很长的错误,现在我甚至无法再显示它们了。尝试在地图上绘制数据时,它不会返回数据并崩溃。

这是执行获取的线程的代码:

package com.example.alexlevine.oceanapp;

import android.os.AsyncTask;

import com
        .google.android.gms.maps.model.LatLng;
import com.google.maps.android.heatmaps.HeatmapTileProvider;
import com.google.maps.android.heatmaps.WeightedLatLng;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import static java.lang.Double.parseDouble;

/**
 * Created by Alex Levine on 8/14/2017.
 */

public class fetchFFDASData extends AsyncTask<URL, Void, List<String[]>> {
    public static ArrayList<WeightedLatLng> ffdasArray;

    protected List<String[]> doInBackground(URL... urls) {

        String typekey;

        ffdasArray = new ArrayList<WeightedLatLng>();
        Object[] ffdasObjects = null;
        URL mUrl = null;
        List<String[]> csvLine = new ArrayList<>();
        String[] content = null;
        try {
            //mUrl = new URL("http://hpcg.purdue.edu/FFDAS/Download/"+MainActivity.typeKey+"_yearly_date="+MainActivity.displayyear+"s-01-01-00_res=0.1_origin=-180,90_size=360,-180.csv");
            mUrl = new URL ("http://hpcg.purdue.edu/FFDAS/Download/" + MainActivity.typeKey + "_yearly_date=" + MainActivity.displayyear + "-01-01-00_res=0.1_origin=-180,90_size=360,-180.csv");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            //assert mUrl != null;
            URLConnection connection = mUrl.openConnection();
            BufferedReader br = new BufferedReader(new
                    InputStreamReader(connection.getInputStream()));
            String line = "";
            while((line = br.readLine()) != null){
                content = line.split(",");
                csvLine.add(content);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int i = 3; i < /*csvLine.size()*/7; i++) {
            double lt = Double.parseDouble(csvLine.get(i)[0]);
            double ln = Double.parseDouble(csvLine.get(i)[2]);
            double w = Double.parseDouble(csvLine.get(i)[2]);
            LatLng ltln = new LatLng(lt, ln);
            WeightedLatLng wll = new WeightedLatLng(ltln, w);
            ffdasArray.add(wll);
        }
        return null;
    }

    protected void onPostExecute(List<String[]> result) {
        super.onPostExecute(result);
        //
        }
    }

这是我的主要活动:

 package com.example.alexlevine.oceanapp;

import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.TileOverlayOptions;
import com.google.maps.android.heatmaps.HeatmapTileProvider;
import com.google.maps.android.heatmaps.WeightedLatLng;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import static com.example.alexlevine.oceanapp.R.id.seekBar;

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

    public static SeekBar seekbar;

    public static GoogleMap mGoogleMap;
    private HeatmapTileProvider mProvider;

    public static TextView minyear;
    public static TextView maxyear;
    public static TextView currentyeartext;
    public static int displayyear;
    public static boolean usingSOCAT;
    public static String typeKey;
    public static Spinner dropdown;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (googleServicesAvailable()) {
            Toast.makeText(this, "Play services available", Toast.LENGTH_LONG).show();;
            initMap();

            //get the spinner from the xml.
            dropdown = (Spinner)findViewById(R.id.spinner);
            //create a list of items for the spinner.
            String[] items = new String[]{"Ocean CO2 Densities", "Land CO2 Emissions (all sources)", "Electricity CO2 Emissions", "Aviation CO2 Emissions", "Ocean Shipping CO2 Emissions"};
            //create an adapter to describe how the items are displayed, adapters are used in several places in android.
            //There are multiple variations of this, but this is the basic variant.
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);
            //set the spinners adapter to the previously created one.
            dropdown.setAdapter(adapter);


            currentyeartext = (TextView) findViewById(R.id.currentyear);

            minyear = (TextView) findViewById(R.id.minyear);
            maxyear = (TextView) findViewById(R.id.maxyear);

            typeKey = "00totals";
            dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
                {
                    switch (position) {
                        case 0: {
                            usingSOCAT = true;
                            displayyear = 1957;
                            seekbar.setMax(58);
                            minyear.setText("1957");
                            maxyear.setText("2015");
                            break;
                        }
                        case 1: {
                            usingSOCAT = false;
                            displayyear = 1997;
                            minyear.setText("1997");
                            maxyear.setText("2010");
                            seekbar.setMax(14);
                            typeKey = "00totals";
                            break;
                        }
                        case 2: {
                            usingSOCAT = false;
                            displayyear = 1997;
                            minyear.setText("1997");
                            maxyear.setText("2010");
                            seekbar.setMax(14);
                            typeKey = "01elec";

                            // Whatever you want to happen when the thrid item gets selected
                            break;
                        }
                        case 3: {
                            usingSOCAT = false;
                            displayyear = 1997;
                            minyear.setText("1997");
                            maxyear.setText("2010");
                            seekbar.setMax(14);
                            typeKey = "11aviation";;
                            // Whatever you want to happen when the thrid item gets selected
                            break;
                        }
                        case 4: {
                            usingSOCAT = false;
                            displayyear = 1997;
                            minyear.setText("1997");
                            maxyear.setText("2010");
                            seekbar.setMax(14);
                            typeKey = "12shipping";
                            // Whatever you want to happen when the thrid item gets selected
                            break;
                        }
                    }
                }
                public void onNothingSelected(AdapterView<?> parent)
                {

                }
            });

            seekbar = (SeekBar) findViewById(seekBar);
            seekbar.setOnSeekBarChangeListener(
                    new SeekBar.OnSeekBarChangeListener() {

                        @Override
                        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                            displayyear = progress + 1997;
                            if(usingSOCAT)
                            {
                                displayyear = progress + 1957;
                                new fetchSOCATData().execute();
                                //createHeatMap(fetchSOCATData.co2array);
                            }
                            else
                            {
                                displayyear = progress + 1997;
                                new fetchFFDASData().execute();
                                //List<WeightedLatLng> calledData = fetchFFDASData.ffdasArray;
                                //List<WeightedLatLng> tryit = new ArrayList<WeightedLatLng>();
                                /*tryit.add(new WeightedLatLng(new LatLng(62, 42), 99));
                                tryit.add(new WeightedLatLng(new LatLng(86, 42), 14));
                                tryit.add(new WeightedLatLng(new LatLng(94, 42), 82));
                                tryit.add(new WeightedLatLng(new LatLng(71, 42), 22));
                                tryit.add(new WeightedLatLng(new LatLng(21, 42), 23));*/
                                //createHeatMap(fetchFFDASData.ffdasArray);
                                minyear.setText((CharSequence) fetchFFDASData.ffdasArray);
                            }
                            currentyeartext.setText("Showing: " + displayyear);
                        }

                        @Override
                        public void onStartTrackingTouch(SeekBar seekBar) {

                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekBar) {

                        }
                    });

            if(usingSOCAT) {

            }
            //new fetchSOCATData().execute();
            /*minyear = (TextView) findViewById(R.id.minyear);
            maxyear = (TextView) findViewById(R.id.maxyear);
            minyear.setText("1957");
            maxyear.setText("2015");*/

            //fetchSOCATData process = new fetchSOCATData();
            //process.execute();

        } else {
            //No maps layout
        }
    }

    //@Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    public void initMap() {
       SupportMapFragment mapFragment = (SupportMapFragment) this.getSupportFragmentManager()
               .findFragmentById(R.id.mapFragment);

       if(mapFragment != null) {
           mapFragment.getMapAsync((OnMapReadyCallback)this);
       }
    }

    public void createHeatMap(List<WeightedLatLng> dataset)
    {
       List<WeightedLatLng> locations = dataset;
       /*mProvider = new HeatmapTileProvider.Builder().weightedData(locations).build();
       mProvider.setRadius( HeatmapTileProvider.DEFAULT_RADIUS );
       mGoogleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
        mProvider = new HeatmapTileProvider();
        mProvider.setWeightedData(dataset);
        mProvider = mProvider.build();*/

        //for (LatLng coordinate : coordinates) {
            //WeightedLatLng weightedCoordinate = new WeightedLatLng(coordinate);
            //com.google.maps.android.geometry.Point point = weightedCoordinate.getPoint();

            // Filter points at infinity
           /* if (Double.isInfinite(point.x) || Double.isInfinite(point.y)) {
                Log.w(TAG, "Attempted to add undefined point " + coordinate);
                continue;
            }
            weightedCoordinates.add(weightedCoordinate);*/
        //}

        mProvider = new HeatmapTileProvider.Builder()
                .weightedData(dataset)
                .opacity(0.5)
                .build();
        mGoogleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));
        Toast.makeText(this, "working", Toast.LENGTH_SHORT).show();
    }

    public void onMapReady(GoogleMap googleMap) {
        mGoogleMap = googleMap;
        goToLocation(-65, -12);
    }

    public void goToLocation(double lat, double lng) {
        LatLng ll = new LatLng(lat, lng);
        CameraUpdate update = CameraUpdateFactory.newLatLng(ll);
        mGoogleMap.moveCamera(update);
    }

    public boolean googleServicesAvailable() {
        GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int isAvailable = api.isGooglePlayServicesAvailable(this);
        if (isAvailable == ConnectionResult.SUCCESS)
            return true;
        else if (api.isUserResolvableError(isAvailable)) {
            Dialog dialog = api.getErrorDialog(this, isAvailable, 0);
            dialog.show();
        } else
            Toast.makeText(this, "Can't connect to play services", Toast.LENGTH_LONG).show();
        return false;
    }


} 

请注意,MainActivity中有其他方法的调用我已在此帖中排除,因为它们不相关,所以这不是错误。但是,有人可以看看我的代码并帮我调试吗?谢谢!

编辑:这是我的错误开始日志:

我看到了一些关于内存分配的信息,但我非常怀疑它们是一个巨大的溢出,因为我只是调用4行数据来测试它。此外,以前,有一些类型的错误显示一些丢失的标题,但我不能再重新创建它。

08-29 01:05:22.311 11369-11378/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 9.873s for cause ObjectsAllocated
08-29 01:05:22.311 11369-11378/com.example.alexlevine.oceanapp I/zygote: Forcing collection of SoftReferences for 32B allocation
08-29 01:05:22.312 11369-11380/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 4.880s for cause HeapTrim
08-29 01:05:22.312 11369-11369/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 5.472s for cause ObjectsAllocated
08-29 01:05:22.312 11369-11856/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:22.312 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:22.312 11369-11378/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:22.312 11369-11379/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:22.313 11369-11369/com.example.alexlevine.oceanapp W/zygote: Throwing OutOfMemoryError "Failed to allocate a 40 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 402653184, growth limit 402653184"
08-29 01:05:22.313 11369-11856/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 27.854s for cause ObjectsAllocated
08-29 01:05:22.313 11369-11856/com.example.alexlevine.oceanapp I/zygote: Starting a blocking GC Alloc
08-29 01:05:22.313 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:22.313 11369-11369/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:22.318 11369-11378/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:22.318 11369-11379/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:23.535 11369-11856/com.example.alexlevine.oceanapp I/zygote: Clamp target GC heap from 389MB to 384MB
08-29 01:05:23.535 11369-11856/com.example.alexlevine.oceanapp I/zygote: Alloc concurrent copying GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 553us total 1.222s
08-29 01:05:23.535 11369-11376/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 2.496s for cause ObjectsAllocated
08-29 01:05:23.535 11369-11376/com.example.alexlevine.oceanapp W/zygote: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 8 free bytes and 8B until OOM, max allowed footprint 402653184, growth limit 402653184" (recursive case)
08-29 01:05:23.536 11369-11378/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 1.223s for cause Alloc
08-29 01:05:23.536 11369-11378/com.example.alexlevine.oceanapp I/zygote: Starting a blocking GC Alloc
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote: "JDWP" daemon prio=5 tid=4 Runnable
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:   | group="system" sCount=0 dsCount=0 flags=0 obj=0x12c467e8 self=0xa7c0bc00
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:   | sysTid=11376 nice=0 cgrp=default sched=0/0 handle=0x96aea970
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:   | state=R schedstat=( 29027554235 2495307398 3483 ) utm=2703 stm=199 core=0 HZ=100
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:   | stack=0x969f0000-0x969f2000 stackSize=1006KB
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:   | held mutexes= "mutator lock"(shared held)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Throwable.toString(Throwable.java:474)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.String.valueOf(String.java:2827)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.StringBuilder.append(StringBuilder.java:132)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:290)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Throwable$WrappedPrintStream.println(Throwable.java:740)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Throwable.printStackTrace(Throwable.java:648)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Throwable.printStackTrace(Throwable.java:636)
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Throwable.printStackTrace(Throwable.java:627)
08-29 01:05:23.536 11369-11379/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:23.536 11369-11369/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:23.536 11369-11376/com.example.alexlevine.oceanapp W/zygote: JNI WARNING: java.lang.OutOfMemoryError thrown while calling printStackTrace
08-29 01:05:23.537 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:23.538 11369-11856/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:25.781 11369-11378/com.example.alexlevine.oceanapp I/zygote: Clamp target GC heap from 389MB to 384MB
08-29 01:05:25.781 11369-11378/com.example.alexlevine.oceanapp I/zygote: Alloc concurrent copying GC freed 10(728B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 1.299ms total 2.245s
08-29 01:05:25.781 11369-11369/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.781 11369-11379/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:25.781 11369-11856/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:25.782 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.782 11369-11369/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 3.469s for cause Alloc
08-29 01:05:25.782 11369-11369/com.example.alexlevine.oceanapp I/zygote: Starting a blocking GC Alloc
08-29 01:05:25.782 11369-11379/com.example.alexlevine.oceanapp I/zygote: WaitForGcToComplete blocked for 3.469s for cause ObjectsAllocated
08-29 01:05:25.782 11369-11369/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.783 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.783 11369-11379/com.example.alexlevine.oceanapp I/zygote: Starting a blocking GC Alloc
08-29 01:05:25.783 11369-11378/com.example.alexlevine.oceanapp W/zygote: Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 0 free bytes and 0B until OOM, max allowed footprint 402653184, growth limit 402653184" (recursive case)
08-29 01:05:25.783 11369-11379/com.example.alexlevine.oceanapp I/zygote: Starting a blocking GC Alloc
08-29 01:05:25.783 11369-11376/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.783 11369-11369/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc
08-29 01:05:25.784 11369-11856/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC ObjectsAllocated
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote: "FinalizerDaemon" daemon prio=5 tid=9 Runnable
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:   | group="system" sCount=0 dsCount=0 flags=0 obj=0x12c863f0 self=0xa5263a00
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:   | sysTid=11378 nice=4 cgrp=default sched=0/0 handle=0x968e8970
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:   | state=R schedstat=( 16464684522 913376415 1721 ) utm=1514 stm=132 core=0 HZ=100
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:   | stack=0x967e6000-0x967e8000 stackSize=1038KB
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:   | held mutexes= "mutator lock"(shared held)
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:     at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:53)
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Daemons$Daemon.run(Daemons.java:103)
08-29 01:05:25.784 11369-11378/com.example.alexlevine.oceanapp W/zygote:     at java.lang.Thread.run(Thread.java:764)
08-29 01:05:25.786 11369-11378/com.example.alexlevine.oceanapp E/System: Uncaught exception thrown by finalizer
08-29 01:05:25.786 11369-11378/com.example.alexlevine.oceanapp I/zygote: Waiting for a blocking GC Alloc 

1 个答案:

答案 0 :(得分:0)

您可以使用库来处理网络调用,例如http://square.github.io/okhttp/

,而不是手动使用异步任务

如果您要使用异步任务,则在从异步任务对象访问静态数组时会出错。而是覆盖后执行,然后在您的活动中设置数据

public class fetchFFDASData extends AsyncTask<URL, Void, ArrayList<WeightedLatLng>> {
    public static ArrayList<WeightedLatLng> ffdasArray;

    protected List<String[]> doInBackground(URL... urls) {

        String typekey;

        ffdasArray = new ArrayList<WeightedLatLng>();
        Object[] ffdasObjects = null;
        URL mUrl = null;
        List<String[]> csvLine = new ArrayList<>();
        String[] content = null;
        try {
            //mUrl = new URL("http://hpcg.purdue.edu/FFDAS/Download/"+MainActivity.typeKey+"_yearly_date="+MainActivity.displayyear+"s-01-01-00_res=0.1_origin=-180,90_size=360,-180.csv");
            mUrl = new URL ("http://hpcg.purdue.edu/FFDAS/Download/" + MainActivity.typeKey + "_yearly_date=" + MainActivity.displayyear + "-01-01-00_res=0.1_origin=-180,90_size=360,-180.csv");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            //assert mUrl != null;
            URLConnection connection = mUrl.openConnection();
            BufferedReader br = new BufferedReader(new
                    InputStreamReader(connection.getInputStream()));
            String line = "";
            while((line = br.readLine()) != null){
                content = line.split(",");
                csvLine.add(content);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int i = 3; i < /*csvLine.size()*/7; i++) {
            double lt = Double.parseDouble(csvLine.get(i)[0]);
            double ln = Double.parseDouble(csvLine.get(i)[2]);
            double w = Double.parseDouble(csvLine.get(i)[2]);
            LatLng ltln = new LatLng(lt, ln);
            WeightedLatLng wll = new WeightedLatLng(ltln, w);
            ffdasArray.add(wll);
        }
        return ffdasArray;
    }

    protected void onPostExecute(ArrayList<WeightedLatLng> result) {
        super.onPostExecute(result);
        //
        }
    }

现在,您在Activity中对异步任务的调用将是

else
   {
     displayyear = progress + 1997;
     new fetchFFDASData(){
@ovveride
protected void onPostExecute(ArrayList<WeightedLatLng> result) {
        super.onPostExecute(result);
// minyear.setText();
        // do the processing here.
        }
    }
}.execute();


}