gpt4 book ai didi

java - NullpointerException 在 Canvas 上绘制位图

转载 作者:行者123 更新时间:2023-12-01 15:49:02 28 4
gpt4 key购买 nike

为什么我会收到 NullpointerException?

谢谢!

PS:我是 Java 新手。

    try {
URL uri = new URL("http://static.panoramio.com/photos/original/41455707.jpg");
URLConnection connection = uri.openConnection();
Log.i(TAG, "connecting...");
connection.connect();
InputStream is = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024);
Bitmap bmp = BitmapFactory.decodeStream(bis);
bis.close();
is.close();

Log.i(TAG, "setting bitmap");
//Log.d(TAG, canvas.toString());
//Log.d(TAG, bmp.toString());
canvas.setBitmap(bmp);
} catch (Exception exc){
Log.e(TAG, exc.toString());
return;
}

输出:

06-28 17:29:04.857   391   397 I MyWallpaperPainting: connecting...
06-28 17:29:07.248 391 397 I MyWallpaperPainting: setting bitmap
06-28 17:29:07.248 391 397 E MyWallpaperPainting: java.lang.NullPointerException

最佳答案

这可能很愚蠢,但是您之前是否在某处初始化了 Canvas ?

关于java - NullpointerException 在 Canvas 上绘制位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6509029/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com