我在 android 中设置墙纸时遇到问题。我使用了以下代码,但它不起作用。
这是代码:
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
public void onClick(DialogInterface dialog, int item) {
// TODO Auto-generated method stub
try {
wallpaperManager.setBitmap(i.getDrawingCache());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
return i;
}
谁能帮帮我!!@谢谢!!
错误:
我得到Null pointer exception
:
04-03 12:52:29.344: E/AndroidRuntime(600): FATAL EXCEPTION: main
04-03 12:52:29.344: E/AndroidRuntime(600): java.lang.NullPointerException
04-03 12:52:29.344: E/AndroidRuntime(600): at com.example.androiddatingapp.gallery$1$1.onClick(gallery.java:74)
04-03 12:52:29.344: E/AndroidRuntime(600): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.widget.ListView.performItemClick(ListView.java:3513)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.os.Handler.handleCallback(Handler.java:587)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
04-03 12:52:29.344: E/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-03 12:52:29.344: E/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 12:52:29.344: E/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:507)
04-03 12:52:29.344: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-03 12:52:29.344: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-03 12:52:29.344: E/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)