zoukankan      html  css  js  c++  java
  • 错误 No enclosing instance of type WallpaperService is available due to some intermediate constructor invocation

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

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


    错误代码:

    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. ……  



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

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

    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. }   




    正确修改后为:

    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.     ……  
  • 相关阅读:
    Django基于Form之登录和注册
    python中函数参数*args和**kw的区别
    django用户认证系统——自定义认证后台8
    django用户认证系统——重置密码7
    django用户认证系统——修改密码6
    django用户认证系统——注销和页面跳转5
    关于Shiro的盐值加密法的使用
    Shiro的登录验证【基于SpringMVC框架下】
    Shrio的登录验证过程中的密码验证,过程,及relam在applicationContext.xml的配置
    taglib自定义标签的使用
  • 原文地址:https://www.cnblogs.com/sode/p/2319889.html
Copyright © 2011-2022 走看看