triniwiz / nativescript-downloader

Apache License 2.0
32 stars 18 forks source link

ERROR Error: java.lang.NullPointerException #25

Closed alereisan closed 6 years ago

alereisan commented 6 years ago

tns --version 4.2.3 "nativescript-downloader": "2.1.0",

Trying a simple example, I get this error when calling .createDownload()

ERROR Error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String co.fitcom.fancydownloader.ManagerService.create(co.fitcom.fancydownloader.Request)' on a null object reference co.fitcom.fancydownloader.Manager.create(Manager.java:57) com.tns.Runtime.callJSMethodNative(Native Method) com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) com.tns.Runtime.callJSMethodImpl(Runtime.java:996) com.tns.Runtime.callJSMethod(Runtime.java:983) com.tns.Runtime.callJSMethod(Runtime.java:967) com.tns.Runtime.callJSMethod(Runtime.java:959) com.tns.gen.java.lang.Runnable.run(Runnable.java:15) android.os.Handler.handleCallback(Handler.java:790) android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loop(Looper.java:172) android.app.ActivityThread.main(ActivityThread.java:6590) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

my implementation:

    createLocalVideo() {
        let documents = knownFolders.documents();
        this.folder = documents.getFolder("localVideoTest");
        console.log(this.folder.path);
        const downloader = new Downloader();
        const download = downloader.createDownload({
            url: 'http://iascreenmanager.blob.core.windows.net/18d8aec5-7ca1-49b4-9cb3-3ac320f59868/YOO_CRM_Promoscreen_TA_201_636650100747088500.mp4',
            path: this.folder.path
        });
        console.log("start download");
        downloader.start(download, (progressData: ProgressEventData) => {
            console.log("progress of download: " + progressData.currentSize + ' / ' + progressData.totalSize + ' MB');
        })
            .then((completed: DownloadEventData) => {
                console.log(`Image : ${completed.path}`);
                log("File successfully downloaded: " + JSON.stringify(completed));
                this.videoLocalPath = completed.path;
            })
            .catch(error => {
                console.log(error.message);

            });
    }
triniwiz commented 6 years ago

Did you call the init ?

alereisan commented 6 years ago

@triniwiz Yes, in app.component.ts ngOnInit()

triniwiz commented 6 years ago

Can you try moving it to the main.ts

alereisan commented 6 years ago

@triniwiz does not work either, same error

triniwiz commented 6 years ago

That error happens when the download service has not started

triniwiz commented 6 years ago

Please upgrade to the latest version