Christian Kurzke
Christian Kurzke

Reputation: 80

Why does Canvas.drawVertices thrown a null pointer exception when not passing a Paint object?

According to the [Canvas.drawVertices Javadoc](http://developer.android.com/reference/android/graphics/Canvas.html#drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint)) it is valid to pass null as Paint, if also the texs parameter is null.

paint Specifies the shader to use if the texs array is non-null

When calling the drawVertices method with a null for Paint, this will cause a Null Pointer Exception.

Upvotes: 0

Views: 506

Answers (1)

zapl
zapl

Reputation: 63955

because internally it calls

nativeDrawVertices(mNativeCanvas, mode.nativeInt, vertexCount, verts,
                   vertOffset, texs, texOffset, colors, colorOffset,
                  indices, indexOffset, indexCount, paint.mNativePaint);

and paint.mNativePaint will cause a NullPointerException if paint is null. The doc forgot to tell you that paint can't be null here :)

Also painting vertices without paint does not seem to be logical since paint defines the line type etc. And the doc does not state paint is optional.

Upvotes: 1

Related Questions