2012-04-26 37 views
0

根據[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))如果參數爲null,則可以將null作爲Paint傳遞。爲什麼Canvas.drawVertices在不傳遞Paint對象時拋出空指針異常?

塗料指定是否texs陣列爲非空

當調用drawVertices方法與null爲塗料使用着色器,這將導致一個空指針異常。

回答

1

,因爲在內部調用

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

paint.mNativePaint會導致一個NullPointerException如果塗料爲null。該文件忘了告訴你,油漆不能爲空:)

還沒有繪畫的頂點繪畫似乎並不合邏輯,因爲油漆定義線的類型等等,而文檔沒有指出paint is optional

+0

感謝您的回答。我的用例是使用'colors'數組來定義三角形填充的顏色。 (現在搞定了) – 2012-04-26 21:12:13