执行AsyncTask时出现DeadObjectException

时间:2019-05-26 17:00:14

标签: android

我在执行代码时遇到DeadObject异常。我试图从在线获取数据,以便可以将其显示在列表视图中。甚至无法获取数据。我给出了代码我正在努力。调用了Getvv函数,还调用了Background函数,但是结果为null,因此onPostExecute中也存在null指针异常。请帮帮我!

package r.vavy.android;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity   {



    String currentVersion = null;
    String packa_name="";
    ArrayList<String> arrlist=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        for(int i=0;i<arrlist.size();i++)
        {
            String ppp_name=arrlist.get(i);
            String name_app="www.example.com/"+ppp_name;
            new Getvv().execute(name_app);
        }


    }
    public class Getvv extends AsyncTask<String,String ,String >
    {
        @Override
        protected String doInBackground(String... strings) {
            String newVersion = null;
            try {
                Document document = Jsoup.connect(strings[0])
                        .timeout(30000)
                        .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                        .referrer("http://www.google.com")
                        .get();
                if (document != null) {
                    Elements element = document.getElementsContainingOwnText("Test Connect");
                    for (Element ele : element) {
                        if (ele.siblingElements() != null) {
                            Elements sibElemets = ele.siblingElements();
                            for (Element sibElemet : sibElemets) {
                                newVersion = sibElemet.text();
                            }
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return newVersion;
        }
        @Override
        protected void onPostExecute(String s) {

            Log.i("rest_five ",s);
        }
    }
}
`

0 个答案:

没有答案