在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;
}
答案 0 :(得分:0)
您使用了课程BlackPixel
而不是您的字段blackPixel
。
只需在该行中用小写字母b写blackPixel
。