Field xxx is never assigned to, and will always have its default value null

前端 未结 4 1285
南方客
南方客 2020-12-17 18:26

Anyone know whats this problem?

I got this warning Field xxx is never assigned to, and will always have its default value null on private sta

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 19:26

    You are never assigning an instance of the Quantizer class to your quantit static variable, so it will remain a null reference and will generate that exception when you'll try to use one of its methods. To fix the problem, just initialize that member with a new Quantizer object before using it.

    By the way, I'm not sure you want that variable to be static.

    Edit

    I saw just now that Quantizer is an abstract class... then you can't instantiate it directly, you have first to derive your specific class from it implementing the abstract methods (namely QuantizePixel and GetPalette) or use another ready-made class deriving from Quantizer, and then initialize the quantit field with a new instance of such class.

提交回复
热议问题