简体   繁体   English

layoutroot无法解析

[英]layoutroot can't be resolved

I'm a newbie in android java programming, and I have a code to take a screenshot: 我是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();
            }

it gives the error: 它给出了错误:

"layoutroot cannot be resolved or is not a field" “ layoutroot无法解析或不是字段”

I don't know if I have to define "layoutroot", just don't know! 我不知道是否必须定义“ layoutroot”,只是不知道! could anyone help me to solve this problem? 谁能帮我解决这个问题? thank you! 谢谢!

There is a typo, when you have: 有错字时,您有:

View content = findViewById(R.id.layouroot);

You are missing a 't', it should be: 您缺少“ t”,应该是:

View content = findViewById(R.id.layoutroot);

Check, if you have imported android.R 检查是否已导入 android.R

than Remove following import 比删除以下导入

import android.R;

it should be: 它应该是:

import your.application.packagename.R;

Edit 编辑

you will also have to define layoutroot 您还必须定义 layoutroot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM