有一DownloadTask类代码如下
public class DownloadTask extends AsyncTask<String, Integer, Integer> {
     ................    private Context context;
    LayoutInflater factory = LayoutInflater.from(context);
    View layout = factory.inflate(R.layout.activity_main, null);

    ProgressBar downloadProgress = (ProgressBar) layout.findViewById(R.id.download_progress);    public DownloadTask(DownloadListener listener, Context context) {
        this.listener = listener;
        this.context = context;
    }....................
}
在DownloadService中使用
private DownloadTask downloadTask ;
downloadTask = new DownloadTask(listener,DownloadService.this);红色字体为空指针位置大神们帮忙看看吧,万分感谢!!!

解决方案 »

  1.   

    public class DownloadTask extends AsyncTask<String, Integer, Integer> {
         ................    private Context context;
        LayoutInflater factory = LayoutInflater.from(context);
        View layout = factory.inflate(R.layout.activity_main, null);
        ProgressBar downloadProgress = (ProgressBar) layout.findViewById(R.id.download_progress);    public DownloadTask(DownloadListener listener, Context context) {
            this.listener = listener;
            this.context = context;
    factory = LayoutInflater.from(context);
        View layout = factory.inflate(R.layout.activity_main, null);
        ProgressBar downloadProgress = (ProgressBar) layout.findViewById(R.id.download_progress);    }
    ....................
    }
      

  2.   

    public class DownloadTask extends AsyncTask<String, Integer, Integer> {
         ................    private Context context;
        LayoutInflater factory;
        View layout ;
        ProgressBar downloadProgress;    public DownloadTask(DownloadListener listener, Context context) {
            this.listener = listener;
            this.context = context;
           factory = LayoutInflater.from(context);
        layout = factory.inflate(R.layout.activity_main, null);
        downloadProgress = (ProgressBar) layout.findViewById(R.id.download_progress);
        }
    ....................
    }