错误 No enclosing instance of type WallpaperService is available due to some intermediate constructor ...

引用:http://blog.csdn.net/You_and_Me12/article/details/7173825

No enclosing instance of type WallpaperService is available due to some intermediate constructor invocation


错误代码:

 

[java]  view plain copy print ?
  1. import android.app.Service;  
  2. import android.os.Bundle;  
  3. import android.service.wallpaper.WallpaperService;  
  4. import android.service.wallpaper.WallpaperService.Engine;  
  5. import android.view.MotionEvent;  
  6. import android.view.SurfaceHolder;  
  7.   
  8. public class MyEngine extends Engine{  
  9.       
  10. ……  



 

才发现是继承了内隐类了,查找了一下

参考引文如下:点击打开链接

 

[plain]  view plain copy print ?
  1. 这是在《JAVA编程思想》上看到的一道例题,是关于继承inner   classes(内隐类)的。   
  2.   
  3. 先把代码和书上的一些原话写出来,如下:   
  4.   
  5. 由于inner   class的构造函数必须连接到一个reference指向outer   class   对象身上,所以   
  6. 当你继承inner   class时,事情便稍微复杂些。问题出在“指向outer   class对象”的那个   
  7. 神秘reference必须被初始化。但derived   class之内不存在可连接的缺省对象,这个问题   
  8. 的答案是,使用专用语法,明确产生该关联性:   
  9.   
  10. class   WithInner   {   
  11.         class   Inner{}   
  12. }   
  13.   
  14. public   class   InheritInner   extends   WithInner.Inner   {   
  15.         InheritInner(WithInner   wi)   {   
  16.                 wi.super();                   //---这里不懂,wi.super()指的是什么,有什么用?   
  17.         }   
  18.         public   static   void   main(String[]   args)   {   
  19.                 WithInner   wi   =   new   WithInner();   
  20.                 InheritInner   ii   =   new   InheritInner(wi);   
  21.         }   
  22. }   



 


正确修改后为:

 

[java]  view plain copy print ?
  1. import android.app.Service;  
  2. import android.os.Bundle;  
  3. import android.service.wallpaper.WallpaperService;  
  4. import android.service.wallpaper.WallpaperService.Engine;  
  5. import android.view.MotionEvent;  
  6. import android.view.SurfaceHolder;  
  7.   
  8. public class MyEngine extends Engine{  
  9.       
  10.     public MyEngine(WallpaperService wp) {//添加的  
  11.         wp.super();  
  12.     }  
  13.     ……  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值