int cannot be dereferenced

后端 未结 3 868
谎友^
谎友^ 2020-11-30 15:19

I am beginning in java (I\'m learning in microedition) and I got this error: \"int cannot be dereferenced\" in the following class:

class DCanvas extends Can         


        
3条回答
  •  孤街浪徒
    2020-11-30 15:39

    The g in drawString is the color value you've passed in, not your Graphics reference. So the error is when you're trying to call a method on an int, which you can't do.

    //            Passing an integer 'g' into the function here |
    //                                                          V
    public void drawString(String str, int x, int y, int r, int g, int b){
    //  | This 'g' is the integer you passed in
    //  V
        g.setColor(r, g, b);
        g.drawString(str, x, y, 0);
    }
    

提交回复
热议问题