【发布时间】:2013-11-25 17:11:50
【问题描述】:
在 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;
}
【问题讨论】:
-
how can i fix that,不要在非静态方法中引用静态方法
标签: android reference static non-static