0

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
4

5 に答える 5

1

これはばかげているかもしれませんが、キャンバスを以前にどこかで初期化しましたか?

于 2011-06-28T15:36:04.943 に答える
0

InputStreamは抽象クラスです。インスタンスを作成できるとは思いませんが、試してみましたか。

BufferedInputStream bis = new BufferedInputStream(new InputStream(connection.getInputStream())、8 * 1024);

于 2011-06-28T16:17:20.083 に答える
0

それはオーバーライドされた onDraw (Canvas canvas) メソッドの 1 つですか?

于 2011-06-28T15:39:38.597 に答える
0

私はゲーム開発が得意ではありませんが、SurfaceView から拡張して Surface.CallBack を実装し、内部の AsyncTask クラスを使用してスレッドを処理しないのはなぜですか? きちんと仕事をします!=]

于 2011-06-28T22:53:57.113 に答える
0

キャンバス オブジェクトを初期化していないと思います。

于 2011-06-28T15:35:34.277 に答える