本文介绍了动态壁纸中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 大家好, 我在活壁纸上收到错误请帮助我 我的代码是 壁纸引擎 公共类MywallpaperEngine扩展引擎{ //私人决赛DottedCircles circles = new DottedCircles(); private final MovingBackGround circles1 = new MovingBackGround( getApplication()); private final runnable mRunnable = new Runnable(){ public void run(){ drawFrame(); } }; private boolean mVisible = false; 私人长tapTime; 私人浮动tapX; 私人浮动tapY; public void onCreate(SurfaceHolder holder){ super.onCreate(holder); setTouchEventsEnabled(true); } public void onDestroy( ){ super.onDestroy(); mHandler.removeCallbacks(mRunnable); } public void onVisibilityChanged(boolean visible){ mVisible = visible; drawFrame(); } public void onSurfaceChanged(SurfaceHolder holder,int format, int width,int height){ super.onSurfaceChanged(持有人,格式,宽度,高度); circles1.init(宽度,高度); drawFrame(); } public void onSurfaceDestroyed(SurfaceHolder holder){ super.onSurfaceDestroyed(holder); mVisible = false; 尝试 { 线程更新器= null; updater.join() ; } catch(InterruptedException e) { } super.onSurfaceDestroyed(holder); drawFrame(); } / * * public void onOffsetsChanged(float xOffset,float yOffset,float * xStep,float yStep,int xPixels,int yPixels){if(xPixels!= * circles.getOffset()){circles。 setOffset(XPIXELS); if(mVisible){ * drawFrame(); } $} * / public void onTouchEvent(MotionEvent事件){ / * if(event) .getAction()== MotionEvent.ACTION_DOWN){ tapTime = event.getEventTime(); tapX = event.getX(); tapY = event.getY(); }否则if(event.getAction()== MotionEvent.ACTION_UP && event.getEventTime() - tapTime < 250 && Math.abs(event.getX() - tapX)< 4 && Math.abs(event.getY( ) - tapY)< 4){ // circles.add(tapX,tapY); } * / } / * private void animate(){ mHandler.removeCallbacks(mRunnable); if(mVisible){ drawFrame(); mHandler.postDelayed(mRunnable,10); } } * / private void drawFrame(){ SurfaceHolder holder = getSurfaceHolder(); Canvas ca nvas = null; 尝试{ canvas = holder.lockCanvas(); if(canvas!= null){ Log.d(call,+ canvas); circles1.draw(canvas); } } catch(NullPointerException异常) { Log.d(空指针,空指针); } 最后{ if(canvas!= null){ holder.unlockCanvasAndPost (画布); } mHandler.removeCallbacks(mRunnable); if(mVisible){ // drawFrame(); mHandler.postDelayed(mRunnable,10); } } } } movingbackgroundclass public MovingBackGround(Context context){ super(context); bg = new BackgroundSelector(); setWillNotDraw(f (b)b $ b私有上下文getApplication(){ 返回null; } @Override protected void onDraw(Canvas canvas){ super.onDraw(画布); if(bg.click == 0) { backGround = BitmapFactory.decodeResource(getResources(), R.drawable.b1); } 否则if(bg.click == 1) { backGround = BitmapFactory。 decodeResource(getResources(), R.drawable.b1); } else if(bg.click == 2) { backGround = BitmapFactory.decodeResource(getResources(), R.drawable.b2); } doDrawRunning(画布); invalidate(); } @Override public void surfaceChanged(SurfaceHolder holde r,int format,int width, int height){ } @Override public void surfaceCreated(SurfaceHolder holder){ } @Override public void surfaceDestroyed(SurfaceHolder holder){ } / ** *绘制游戏Canvas的当前状态。 * / private int mBGFarMoveX = 0; private int mBGNearMoveX = 0; private int width; private int height; private void doDrawRunning(Canvas帆布){ int newFarX = backGround.getWidth() - (-mBGFarMoveX); BitmapFactory.Options options = new BitmapFactory.Options(); Log.d(option ,+选项); options.inPurgeable = true; 资源res = getResources(); Log.d(rrrrrrrrr,+ bmp); bmp = BitmapFactory.decodeResource(res,bmp1 [bgNumber],options); DisplayMetrics metrics1 = new DisplayMetrics(); MovingBackGround context = this; metrics1 = context.getResources()。getDisplayMetrics(); float xScale =(float)canvas.getWidth()/ bmp.getWidth (); float yScale =(float)canvas.getHeight()/ bmp.getHeight(); float scale = Math.max(xScale,yScale); //选择较大的尺寸来增长图像 // scale =(float)(scale * 1.1); //这可以确保图像覆盖整个屏幕。 float scaledWidth = scale * bmp.getWidth(); float scaledHeight = scale * bmp.getHeight(); bmp = Bitmap.createScaledBitmap(bmp,(int)scaledWidth,(int)scaledHeight ,true); float xScale1 =(float)canvas.getWidth()/ backGround.getWidth(); float yScale1 =( float)canvas.getHeight()/ backGround.getHeight(); float scale1 = Math.max(xScale,yScale); //选择较大的尺寸来增长图像 // scale =(float)(scale * 1.1); //这可以确保图像覆盖整个屏幕。 float scaledWidth1 = scale * backGround.getWidth(); float scaledHeight1 = scale * backGround.getHeight(); b $ b backGround = Bitmap.createScaledBitmap(backGround,(int)scaledWidth1,(int)scaledHeight1 ,true); canvas.drawBitmap(backGround,0,0,null); canvas.drawBitmap(bmp,0,0,null); if(runUp = true) { bgNumber + = 1; Log.d(bnum,+ bgNumber); if(bgNumber == bmp1 .length){ bgNumber = 0; runUp = false; } } else if(runUp = false){ bgNumber - = 1; if(bgNumber == 0){ bgNumber + = 1; runUp = true; } } bmp.recycle(); } public void init(int width,int height){ this.width = width; this.height = height; } // TODO自动生成的方法存根 } backgroundselector类 公共类BackgroundSelector扩展活动 { ImageView b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,img; static int click = 0; //静态位图bgImage1; //私有资源mResources; MovingBackGround mv ; @覆盖 public void onCreate(Bundle instanceState) { super.onCreate(instanceState); / * context = this; if(instanceState!= null) { //恢复任何保存的实例状态是否存在 } // setCo ntentView(R.layout.my); * / setContentView(R.layout.my2); // bgImage1 = BitmapFactory。 decodeResource(mResources,R.drawable.b1); b1 =(ImageView)findViewById(R.id.s1); b2 =(ImageView)findViewById(R。 id.s2); b3 =(ImageView)findViewById(R.id.s3); b4 =(ImageView)findViewById(R.id.s4); b5 =(ImageView)findViewById(R.id.s5); b6 =(ImageView)findViewById(R.id.s6); b7 =(ImageView)findViewById(R.id.s7); b8 =(ImageView)findViewById(R.id.s8); b9 =(ImageView) findViewById(R.id.s9); b10 =(ImageView)findViewById(R.id.s10); img =(ImageView)findViewById(R.id。 imageView1); img.setBackgroundResource(R.drawable.s1); b1.setOnClickListener(new OnClickListener(){ @Override public void onClick(查看v) { click = 1 ; Log.d(click1,+ click); mv = new MovingBackGround(getApplication()); img.setBackgroundResource(R.drawable.s1) ; 完成(); } }); b2.setOnClickListener(新的OnClickListener(){ @Override public void onClick(查看v) { click = 2; Log.d(click1,+ click); img.setBackgroundResource(R.drawable.b2); mv = new MovingBackGround(getApplication()); finish(); } }); } } 当我点击setwallpaperbutton&转到主屏幕得到错误Hi All, I am getting error in live wall paper plz help memy code iswallpaper enginepublic class MywallpaperEngine extends Engine {// private final DottedCircles circles = new DottedCircles();private final MovingBackGround circles1 = new MovingBackGround(getApplication());private final Runnable mRunnable = new Runnable() {public void run() {drawFrame();}};private boolean mVisible = false;private long tapTime;private float tapX;private float tapY;public void onCreate(SurfaceHolder holder) {super.onCreate(holder);setTouchEventsEnabled(true);}public void onDestroy() {super.onDestroy();mHandler.removeCallbacks(mRunnable);}public void onVisibilityChanged(boolean visible) {mVisible = visible;drawFrame();}public void onSurfaceChanged(SurfaceHolder holder, int format,int width, int height) {super.onSurfaceChanged(holder, format, width, height);circles1.init(width, height);drawFrame();}public void onSurfaceDestroyed(SurfaceHolder holder) {super.onSurfaceDestroyed(holder);mVisible = false;try { Thread updater = null;updater.join(); } catch (InterruptedException e) { } super.onSurfaceDestroyed(holder);drawFrame();}/* * public void onOffsetsChanged(float xOffset, float yOffset, float * xStep, float yStep, int xPixels, int yPixels) { if (xPixels != * circles.getOffset()) { circles.setOffset(xPixels); if (mVisible) { * drawFrame(); } } } */public void onTouchEvent(MotionEvent event) {/*if (event.getAction() == MotionEvent.ACTION_DOWN) {tapTime = event.getEventTime();tapX = event.getX();tapY = event.getY();} else if (event.getAction() == MotionEvent.ACTION_UP&& event.getEventTime() - tapTime < 250&& Math.abs(event.getX() - tapX) < 4&& Math.abs(event.getY() - tapY) < 4) {// circles.add(tapX, tapY);}*/}/*private void animate() {mHandler.removeCallbacks(mRunnable);if (mVisible) {drawFrame();mHandler.postDelayed(mRunnable,10);}}*/private void drawFrame() {SurfaceHolder holder = getSurfaceHolder();Canvas canvas = null;try {canvas = holder.lockCanvas();if (canvas != null) {Log.d("call", "" + canvas);circles1.draw(canvas);}}catch(NullPointerException exception){Log.d("null pointer","null pointer");}finally {if (canvas != null) {holder.unlockCanvasAndPost(canvas);}mHandler.removeCallbacks(mRunnable);if (mVisible) {//drawFrame();mHandler.postDelayed(mRunnable,10);}}}}movingbackgroundclasspublic MovingBackGround(Context context) {super(context);bg=new BackgroundSelector();setWillNotDraw(false);}private Context getApplication() {// TODO Auto-generated method stubreturn null;}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);if(bg.click==0){backGround = BitmapFactory.decodeResource(getResources(),R.drawable.b1);}else if(bg.click==1){backGround = BitmapFactory.decodeResource(getResources(),R.drawable.b1);}else if(bg.click==2){backGround = BitmapFactory.decodeResource(getResources(),R.drawable.b2);}doDrawRunning(canvas);invalidate();}@Overridepublic void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {}@Overridepublic void surfaceCreated(SurfaceHolder holder) {}@Overridepublic void surfaceDestroyed(SurfaceHolder holder) {}/*** Draws current state of the game Canvas.*/private int mBGFarMoveX = 0;private int mBGNearMoveX = 0;private int width;private int height;private void doDrawRunning(Canvas canvas) {int newFarX = backGround.getWidth() - (-mBGFarMoveX);BitmapFactory.Options options = new BitmapFactory.Options();Log.d("option", ""+options);options.inPurgeable = true;Resources res = getResources();Log.d("rrrrrrrrr", ""+bmp);bmp = BitmapFactory.decodeResource(res,bmp1[bgNumber], options);DisplayMetrics metrics1 = new DisplayMetrics();MovingBackGround context = this;metrics1 = context.getResources().getDisplayMetrics();float xScale = (float) canvas.getWidth() / bmp.getWidth();float yScale = (float) canvas.getHeight() / bmp.getHeight();float scale = Math.max(xScale, yScale); //selects the larger size to grow the images by//scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.float scaledWidth = scale * bmp.getWidth();float scaledHeight = scale * bmp.getHeight();bmp = Bitmap.createScaledBitmap(bmp, (int)scaledWidth, (int)scaledHeight, true);float xScale1 = (float) canvas.getWidth() / backGround.getWidth();float yScale1 = (float) canvas.getHeight() / backGround.getHeight();float scale1= Math.max(xScale, yScale); //selects the larger size to grow the images by//scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.float scaledWidth1 = scale * backGround.getWidth();float scaledHeight1= scale * backGround.getHeight();backGround = Bitmap.createScaledBitmap(backGround, (int)scaledWidth1, (int)scaledHeight1, true);canvas.drawBitmap(backGround, 0, 0, null);canvas.drawBitmap(bmp, 0,0,null);if (runUp = true){ bgNumber += 1;Log.d("bnum", ""+bgNumber); if (bgNumber == bmp1.length){ bgNumber=0; runUp = false; } }else if(runUp = false){ bgNumber -= 1; if (bgNumber == 0){ bgNumber+=1; runUp = true; } }bmp.recycle();}public void init(int width, int height) {this.width = width;this.height = height;}// TODO Auto-generated method stub}backgroundselector classpublic class BackgroundSelector extends Activity{ImageView b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,img;static int click=0;//static Bitmap bgImage1;// private Resources mResources; MovingBackGround mv;@Overridepublic void onCreate(Bundle instanceState){super.onCreate(instanceState);/*context = this;if(instanceState != null){// restore any saved instance state if it exists}//setContentView(R.layout.my);*/setContentView(R.layout.my2);//bgImage1 = BitmapFactory.decodeResource(mResources, R.drawable.b1);b1=(ImageView)findViewById(R.id.s1);b2=(ImageView)findViewById(R.id.s2);b3=(ImageView)findViewById(R.id.s3);b4=(ImageView)findViewById(R.id.s4);b5=(ImageView)findViewById(R.id.s5);b6=(ImageView)findViewById(R.id.s6);b7=(ImageView)findViewById(R.id.s7);b8=(ImageView)findViewById(R.id.s8);b9=(ImageView)findViewById(R.id.s9);b10=(ImageView)findViewById(R.id.s10);img=(ImageView)findViewById(R.id.imageView1); img.setBackgroundResource(R.drawable.s1);b1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { click=1; Log.d("click1", ""+click); mv=new MovingBackGround(getApplication()); img.setBackgroundResource(R.drawable.s1); finish(); } });b2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { click=2; Log.d("click1", ""+click); img.setBackgroundResource(R.drawable.b2); mv=new MovingBackGround(getApplication()); finish(); }});}}when i click on setwallpaperbutton & goto home screen get belown error07-23 17:29:40.020: E/SpannableStringBuilder(15702): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length07-23 17:29:40.020: E/SpannableStringBuilder(15702): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length07-23 17:29:41.045: V/WallpaperService(15702): Display Width=800 Height=128007-23 17:29:43.005: E/SurfaceTextureClient(15702): queueBuffer: error queuing buffer to SurfaceTexture, -1907-23 17:29:43.005: E/SurfaceTextureClient(15702): queueBuffer (handle=0x5d436f20) failed (No such device)07-23 17:29:43.025: E/AndroidRuntime(15702): FATAL EXCEPTION: main07-23 17:29:43.025: E/AndroidRuntime(15702): java.lang.IllegalArgumentException07-23 17:29:43.025: E/AndroidRuntime(15702): at android.view.Surface.unlockCanvasAndPost(Native Method)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.drawFrame(Rain.java:145)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.animate(Rain.java:124)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine.access$0(Rain.java:121)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain$JesuswallpaperEngine$1.run(Rain.java:35)07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Handler.handleCallback(Handler.java:615)07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Handler.dispatchMessage(Handler.java:92)07-23 17:29:43.025: E/AndroidRuntime(15702): at android.os.Looper.loop(Looper.java:137)07-23 17:29:43.025: E/AndroidRuntime(15702): at android.app.ActivityThread.main(ActivityThread.java:4921)07-23 17:29:43.025: E/AndroidRuntime(15702): at java.lang.reflect.Method.invokeNative(Native Method)07-23 17:29:43.025: E/AndroidRuntime(15702): at java.lang.reflect.Method.invoke(Method.java:511)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)07-23 17:29:43.025: E/AndroidRuntime(15702): at dalvik.system.NativeStart.main(Native Method)推荐答案 JesuswallpaperEngine.drawFrame(Rain.java: 145 ) 07-23 17 : 29 : 43 。 025 :E / AndroidRuntime( 15702 ):at com.visusoft.rainwallpaper.RainJesuswallpaperEngine.drawFrame(Rain.java:145)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain Je suswallpaperEngine.animate(Rain.java: 124 ) 07-23 17 : 29 : 43 。 025 :E / AndroidRuntime( 15702 ):at com.visusoft.rainwallpaper.RainJesuswallpaperEngine.animate(Rain.java:124)07-23 17:29:43.025: E/AndroidRuntime(15702): at com.visusoft.rainwallpaper.Rain JesuswallpaperEngine.accessJesuswallpaperEngine.access 这篇关于动态壁纸中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 14:00