爲什麼我得到一個NullpointerException?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
好吧,我開始了一個新的代碼庫,我仍然有這個錯誤,現在我發現,如果我使用另一個網址它的工作原理,所以它的位圖導致的問題!但爲什麼? – nomoral