【问题标题】:Error 1 Cannot create an instance of the abstract interface - C#错误 1 ​​无法创建抽象接口的实例 - C#
【发布时间】:2011-07-24 06:48:43
【问题描述】:

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

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

它有什么问题,因为它编译正确,但是当我尝试下载文件时,它不会触发任何东西,也不会按预期显示消息框

【问题讨论】:

  • 为什么您的问题标题所指的内容不在您的问题正文中?

标签: c# .net class interface mozilla


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    相关资源
    最近更新 更多