0

我正在尝试使用线程实现并行下载,但我所有的解压缩过程都应该是顺序的。众所周知,意图服务将所有未决任务排入队列,因此在我所有下载结束时,我试图启动意图服务。问题是我收到以下错误:

05-30 11:49:10.520: E/AndroidRuntime(18790): FATAL EXCEPTION: main
05-30 11:49:10.520: E/AndroidRuntime(18790): java.lang.RuntimeException: Unable to instantiate service br.com.facilit.target.app.android.util.UnzipService: java.lang.InstantiationException: can't instantiate class br.com.facilit.target.app.android.util.UnzipService; no empty constructor

我的下载主题:

public class DownloadService implements Runnable {

    Activity controller;
    boolean post;
    String urlParent;
    String filePath;
    String destinationPath;
    ResultReceiver mReceiver;
    String typeDownload;
    MetaDados metaDado;
    int index;
    boolean isResuming;

    File jsonFile = new File(Constants.DEST_PATH_PARENT + Constants.JSON_FILES_PATH);
    File jsonTempFile;

    public DownloadService(Activity controller, boolean post, String urlParent, String filePath,
            String destinationPath, ResultReceiver mReceiver, String typeDownload, int index, MetaDados metaDado,
            boolean isResuming) {

        this.controller = controller;
        this.post = post;
        this.urlParent = urlParent;
        this.filePath = filePath;
        this.destinationPath = destinationPath;
        this.mReceiver = mReceiver;
        this.typeDownload = typeDownload;
        this.index = index;
        this.metaDado = metaDado;
        this.isResuming = isResuming;

    }

    @Override
    public void run() {

        Log.d(Constants.DOWNLOAD_AND_UNZIP_SERVICE, "Começando processo de download");

        // ALL DOWNLOAD PROCESS
        // THEN CALL INTENT FOR UNZIP

                final Intent service = new Intent(controller.getApplicationContext(), UnzipService.class);

                service.putExtra("post", false);
                service.putExtra("filePath", filePath);
                service.putExtra("destinationPath", destinationPath);
                service.putExtra("receiver", mReceiver);
                service.putExtra("typeDownload", Constants.HTML);
                service.putExtra("metaDado", metaDado);
                service.putExtra("isResuming", false);

                controller.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {

                        controller.startService(service);

                    }
                });
    }
}

我的解压缩意图服务:

public class UnzipService extends IntentService {

    public UnzipService(String name) {
        super("UnzipService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        String filePath = intent.getStringExtra("filePath");

        for (int i = 0; i < 10; i++) {

            try {
                Thread.sleep(1000);
                Log.d("UnzipService", "Simulando descompactação de arquivo " + filePath);
            } catch (InterruptedException e) {
            }
        }
       }
}

显现:

 <service android:name="br.com.facilit.target.app.android.util.UnzipService"/>
4

1 回答 1

3

作为异常报告,您将其 no empty constructor更改为:

public UnzipService() {
        super("UnzipService");
 }
于 2013-05-30T15:06:53.863 回答