我在Android的Java編程新手,我有一個代碼,以截圖:layoutroot解決不了
View content = findViewById(R.id.layoutroot); //it gives the "layoutroot cannot be resolved or is not a field" error
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File(Environment.getExternalStorageDirectory() + "/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
它給人的錯誤:
"layoutroot cannot be resolved or is not a field"
我不不知道我是否必須定義「layoutroot」,只是不知道! 任何人都可以幫助我解決這個問題?謝謝!
我沒有那個導入。但我沒有在任何地方定義過layoutroot,我有按鈕和列表視圖,但沒有按照說明。我必須定義它嗎? –
仍然沒有解決它 –
是的,你肯定會聲明! –