getActiveWorkbenchWindow() return null 解决办法

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /** 
  2.      * Returns the currently active window for this workbench (if any). Returns 
  3.      * <code>null</code> if there is no active workbench window. Returns 
  4.      * <code>null</code> if called from a non-UI thread. 
  5.      *  
  6.      * @return the active workbench window, or <code>null</code> if there is 
  7.      *         no active workbench window or if called from a non-UI thread 
  8.      */  
  9.     public IWorkbenchWindow getActiveWorkbenchWindow();  

调调用的时候不在UI线程中,所以会返回空,可采用如下办法解决

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {  
  2.                 public void run() {  
  3.                     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();  
  4.                     System.out.println(window);  
  5.                 //做想要做的事情吧。  
  6.               
  7.                 }  
  8.             });  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C语言中,return语句用于从函数中返回一个值。NULL在C语言中是一个宏定义,表示一个空指针常量。当一个函数的返回类型是指针类型时,可以使用return NULL来表示返回一个空指针。这通常用于表示函数执行失败或没有找到所需的结果。例如,如果一个函数在执行过程中发生错误,可以使用return NULL来表示函数执行失败。在这种情况下,返回NULL可以作为一个标志,告诉调用函数发生了错误。需要注意的是,当使用一个指向NULL的指针时,如果尝试访问该指针指向的内容,会导致段错误。因此,在使用指向NULL的指针之前,应该先检查该指针是否为NULL,以避免出现错误。 #### 引用[.reference_title] - *1* [【C语言】函数返回 return ; return 1; return NULL; return 0; 区分](https://blog.csdn.net/feit2417/article/details/80985397)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [C语言指针之NULL](https://blog.csdn.net/weixin_34481217/article/details/125280282)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值