0
我想用Xamarin opengl實現android LiveWallpaper。 但是當我激活LiveWallpaper時,GLSurfaceView在構造函數中拋出空引用異常。Xamarin OpenGL GLSurfaceView構造函數拋出空引用異常
錯誤行: 調用GLSurfaceView的基礎構造函數時調用base(context)。
錯誤細節: 顯示java.lang.NullPointerException:嘗試上的空對象引用調用接口方法 '空隙android.view.SurfaceHolder.addCallback(android.view.SurfaceHolder $回調)'
[Service(Label = "@string/ApplicationName", Permission = "android.permission.BIND_WALLPAPER")]
[IntentFilter(new[] { "android.service.wallpaper.WallpaperService" })]
[MetaData("android.service.wallpaper", Resource = "@layout/MyLiveWallpaper")]
public class OpenGLWallpaperService : WallpaperService
{
public override Engine OnCreateEngine()
{
return new OpenGLWallpaperEngine(this);
}
public class OpenGLWallpaperEngine : Engine
{
private readonly OpenGLWallpaperService _serviceInstance;
public OpenGLWallpaperView GLWallpaperView { get; set; }
public OpenGLWallpaperEngine(OpenGLWallpaperService serviceInstance)
: base(serviceInstance)
{
_serviceInstance = serviceInstance;
}
public override void OnCreate(ISurfaceHolder surfaceHolder)
{
base.OnCreate(surfaceHolder);
GLWallpaperView = new OpenGLWallpaperView(this, _serviceInstance, surfaceHolder);
}
}
}
public class OpenGLWallpaperView : GLSurfaceView
{
private readonly OpenGLWallpaperService.OpenGLWallpaperEngine _engineInstance;
public override ISurfaceHolder Holder { get; }
public OpenGLWallpaperView(OpenGLWallpaperService.OpenGLWallpaperEngine engineInstance,
Context context, ISurfaceHolder surfaceHolder)
: base(context)
{
_engineInstance = engineInstance;
Holder = surfaceHolder;
}
}