我最终遇到了一个奇怪的错误,即android LiveWallpaper catch。当我设置这个 它适用于大约2.3的API:
Canvas canvas = null;
//Keep trying till wallpaper is set.
//Error around here..
try
{
canvas = this._surfaceHolder.lockCanvas(null);
synchronized (this._surfaceHolder)
{
this.onDraw(canvas);
}
}
finally
{
if(canvas != null)
{
this._surfaceHolder.unlockCanvasAndPost(canvas);
}
}
这适用于ICS& Honeycomb(在真实设备上测试)
Canvas canvas = null;
//Keep trying till wallpaper is set.
//Error around here..
try
{
canvas = this._surfaceHolder.lockCanvas(null);
synchronized (this._surfaceHolder)
{
this.onDraw(canvas);
}
}
finally
{
if(canvas != null)
{
this._surfaceHolder.unlockCanvasAndPost(canvas);
}
}
当livewallpaper为“Set”时会发生错误。 (服务失败,“异常锁定服务”) 如何从一次编译中获得它?我不想要两个不同的版本。
答案 0 :(得分:4)
try catch的语法是:
try {
// Code
} catch (<the Exception type to catch> ex) {
// Exception handling code
} finally {
// Code for after
}
注意:程序只会捕获您指定的异常。如果您未涵盖所有可能的例外情况,则不会处理。请参阅Oracle的Java教程中的catch blocks。
答案 1 :(得分:0)
} catch {例外e) //捕获异常的代码 最后} {
}
完全按照Java约定编写代码