0

当图像存储在我尝试过但没有希望的arraylist中时,我怎么能设置壁纸!

这是代码:

final ImageView image = new ImageView(mContext);
image.setImageResource(mImageIds[pos]);                 

try {
    wallpaperManager.setBitmap(image.getDrawingCache());
} catch (IOException e) {
    e.printStackTrace();
}

我尝试使用上面的代码,但它显示NullPointer Exception.

4

1 回答 1

0

您本可以显示更多代码(您的数组如何,图片的字符串名称或 int id)。无论如何我会告诉你我是如何做类似的事情的:

Bitmap bitmap;
    final int[] imgs = new int[] { R.drawable.i1, R.drawable.i2, R.drawable.i3,
            R.drawable.i4, R.drawable.i5, R.drawable.i6, R.drawable.i7,
            R.drawable.i8, R.drawable.i9, R.drawable.i10, };

bitmap = BitmapFactory.decodeResource(getResources(), 
                    imgs[pos]);         
            try {
                getApplicationContext().setWallpaper(bitmap);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
于 2013-04-03T08:56:41.407 回答