[英]layoutroot can't be resolved
我是android java编程的新手,并且我有一个代码可以截图:
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无法解析或不是字段”
我不知道是否必须定义“ layoutroot”,只是不知道! 谁能帮我解决这个问题? 谢谢!
有错字时,您有:
View content = findViewById(R.id.layouroot);
您缺少“ t”,应该是:
View content = findViewById(R.id.layoutroot);
检查是否已导入 android.R
比删除以下导入
import android.R;
它应该是:
import your.application.packagename.R;
编辑
您还必须定义 layoutroot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.