2

I'm a newbie in android java programming, and I have a code to take a screenshot:

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"

I don't know if I have to define "layoutroot", just don't know! could anyone help me to solve this problem? thank you!

Pedro Fraga
  • 119
  • 1
  • 2
  • 9

2 Answers2

1

There is a typo, when you have:

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

You are missing a 't', it should be:

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

Check, if you have imported 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

Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
  • I don't have that import. But I don't have layoutroot defined anywhere, I have buttons and listviews, but not layoutroot. do I have to define it? – Pedro Fraga Jul 20 '13 at 12:47