简体   繁体   中英

Error 1 Cannot create an instance of the abstract interface - C#

ok i know what it means, but i dont know how to solve it here is my interface

        public interface nsIDownloadProgressListener
        {
            nsIDOMDocument getDocument();

            void setDocument(nsIDOMDocument doc);

            void OnDownloadStateChange(short state, nsIDownload aDownload);

            void OnStateChange(nsIWebProgress aWebProgress, nsIRequest aRequest, uint                                    
            aStateFlags, object aStatus, nsIDownload aDownload);

            void OnProgressChange(nsIWebProgress WbProgress, nsIRequest aReq, int         
            curSelfProgress, int maxSelfProgress, int curTotalProgress, int 
            maxTotalProgress, nsIDownload aDownload);

            void OnSecurityChange(nsIWebProgress wbProgress, nsIRequest aReq, uint 
            aState, nsIDownload aDownload);
            }

here is the class i use to inherit the interface

          public class DownloadProgressListenerClass : nsIDownloadProgressListener
          {
              #region nsIDownloadProgressListener Members

              nsIDOMDocument Nothingreturned;

              public nsIDOMDocument getDocument()
              {
                  return Nothingreturned;
              }

              public void setDocument(nsIDOMDocument doc)
              {
              }

              public void OnDownloadStateChange(short state, nsIDownload aDownload)
              {
                  MessageBox.Show(aDownload.getId().ToString());
                  OnDownloadStateChange(state, aDownload);
              }

              public void OnStateChange(nsIWebProgress aWebProgress, nsIRequest aRequest, uint aStateFlags, object aStatus, nsIDownload aDownload)
              {
                  MessageBox.Show(aDownload.getId().ToString());

              }

              public void OnProgressChange(nsIWebProgress WbProgress, nsIRequest aReq, int curSelfProgress, int maxSelfProgress, int curTotalProgress, int maxTotalProgress, nsIDownload aDownload)
              {
                  MessageBox.Show(aDownload.getId().ToString());

              }

              public void OnSecurityChange(nsIWebProgress wbProgress, nsIRequest aReq, uint aState, nsIDownload aDownload)
              {
                  MessageBox.Show(aDownload.getId().ToString());

              }

              #endregion nsIDownloadProgressListener Members
          }


and then i try to add the listener to DLManager which should work and report progress

            DownloadProgressListenerClass DLListener = new DownloadProgressListenerClass();
            DLManager = Xpcom.GetService<nsIDownloadManager>("@mozilla.org/download-manager;1");
            DLManager.addListner(DLListener);

is anything wrong with it because it compiles right but when i try to download a file it doesnt trigger anything and it doesnt show the messagebox as its supposed to do

I suspect your addListener method is expecting an interface type of
nsIDownloadProgressListener in the code line:
DLManager.addListner(DLListener);
If it is so, please change your
DownloadProgressListenerClass DLListener = new DownloadProgressListenerClass();
into
nsIDownloadProgressListener DLListener = new DownloadProgressListenerClass();
If you need explanation, let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM