静态引用非静态方法

时间:2013-11-25 17:11:50

标签: android reference static non-static

在saveImage()中,第一行说:

" Cannot make a static reference to the non-static method  getDrawingCache() 
from the type View " 

我该如何解决?

public class ButtonDraw extends Activity {

    public Canvas myCanvas;
    private BlackPixel blackPixel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.paintingfile);


          blackPixel = new BlackPixel(this);
          setContentView(blackPixel);
          blackPixel.requestFocus();



    } 
       public void saveImage()
        {
          Bitmap bitmap = BlackPixel.getDrawingCache();   //

            try 
                {

                    FileOutputStream fos = openFileOutput("name.png", Context.MODE_PRIVATE);
                    bitmap.compress(CompressFormat.JPEG, 10, fos);

                    fos.close();                            
                } 
                catch (Exception e) 
                {
                    e.printStackTrace();
                }

      }

}



public boolean onOptionsItemSelected(MenuItem item){

        switch(item.getItemId())
        {

        case R.id.menu_paintingfileToast:
            saveImage();
            Toast mToast=Toast.makeText(ButtonDraw.this, "Save Succesfull", Toast.LENGTH_LONG);
            mToast.show();

            return true;
        }

        return false;
    }

1 个答案:

答案 0 :(得分:0)

您使用了课程BlackPixel而不是您的字段blackPixel

只需在该行中用小写字母b写blackPixel