动画壁纸动画强制关闭,当我添加超过10帧?

时间:2010-08-21 23:10:32

标签: java android animation live-wallpaper

我正在尝试用一系列启动动画制作一个简单的livewallpaper .pngs ...

我正在使用

private static final int NUM_RES = 9;
        private final Bitmap[] mPics = new Bitmap[NUM_RES];
        CubeEngine() {
            Resources res = getResources();
            for (int i = 0; i< NUM_RES; i++) {
                int id = res.getIdentifier("boot_0010" + (i + 1), "drawable", "minghai.wallpaper");
                mPics[i] = BitmapFactory.decodeResource(res, id);
            }
        }

9似乎是我能走的最高点。如果我将NUM_RES设置为超过9的任何值,我会关闭一个力。

我的所有文件都标有...... boot_00101.png boot_00102.png boot_00103.png boot_00104.png boot_00105.png boot_00106.png boot_00107.png boot_00108.png boot_00109.png boot_00110.png boot_00111.png boot_00112.png boot_00113.png boot_00114.png 等等...我有大约50张图片即将尝试使用

任何人都知道我应该做什么?

logcat的:

08-21 19:18:43.108: ERROR/AndroidRuntime(6475): FATAL EXCEPTION: main
08-21 19:18:43.108: ERROR/AndroidRuntime(6475): java.lang.NullPointerException
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.graphics.Canvas.drawBitmap(Canvas.java:1115)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawYayoi(YayoiWallpaper.java:166)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawFrame(YayoiWallpaper.java:144)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.onOffsetsChanged(YayoiWallpaper.java:117)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$Engine.doOffsetsChanged(WallpaperService.java:669)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:847)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Looper.loop(Looper.java:123)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invoke(Method.java:521)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at dalvik.system.NativeStart.main(Native Method)

@Yok 非常感谢你做了诀窍....在某种程度上,我似乎无法超过30我得到一个内存错误。很抱歉问,但是你碰巧知道一种更有效的方式来简单地获得一个像我想要实现的动画。

08-22 04:35:03.720: ERROR/AndroidRuntime(8783): FATAL EXCEPTION: main
08-22 04:35:03.720: ERROR/AndroidRuntime(8783): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.nativeCreate(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.<init>(YayoiWallpaper.java:60)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper.onCreateEngine(YayoiWallpaper.java:35)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:814)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Looper.loop(Looper.java:123)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invokeNative(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invoke(Method.java:521)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:1)

for循环更改存在问题:

"boot_0010" + (i + 1)"boot_00" + (100+ (i + 1))

更改的循环应如下所示:

       for (int i = 0; i< NUM_RES; i++) {
            int id = res.getIdentifier("boot_00" + (100 + (i + 1)), "drawable", "minghai.wallpaper");
            mPics[i] = BitmapFactory.decodeResource(res, id);
        }

你的循环问题是早些时候用于获取第10张图像的 boot_001010 而不是 boot_00110 。同样是空指针异常的原因,因为没有boot_001010的图像。

答案 1 :(得分:0)

i 为9时,表达式"boot_0010" + (i + 1)计算为字符串boot_001010;你可能希望它是boot_00110