错误1不能创建抽象接口的实例- c#

本文关键字:实例 接口 抽象 不能 创建 错误 | 更新日期: 2023-09-27 18:03:23

好吧,我知道这是什么意思,但我不知道如何解决它这是我的界面

        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);
            }

是我用来继承接口

的类
          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
          }


然后我尝试将侦听器添加到DLManager,它应该工作并报告进度

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

有什么问题吗因为它编译正确但是当我尝试下载一个文件时它没有触发任何东西它没有显示消息框,因为它应该做

错误1不能创建抽象接口的实例- c#

我怀疑您的addListener方法在代码行中期望接口类型为
nsIDownloadProgressListener:
DLManager.addListner(DLListener);
如果是这样,请将您的
DownloadProgressListenerClass DLListener = new DownloadProgressListenerClass();
更改为
nsIDownloadProgressListener DLListener = new DownloadProgressListenerClass();
如果您需要解释,请告诉我