2

我是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”,只是不知道!谁能帮我解决这个问题?谢谢你!

4

2 回答 2

1

有一个错字,当你有:

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

你错过了一个't',它应该是:

View content = findViewById(R.id.layoutroot);
于 2013-07-20T12:45:34.483 回答
0

检查,如果你已经导入 android.R

比删除以下导入

import android.R;

它应该是:

import your.application.packagename.R;

编辑

您还必须定义 layoutroot

于 2013-07-20T12:44:26.463 回答