Android getDrawingCache始终返回null,即使我做了人们推荐的stackoverflow的所有操作

Android getDrawingCache始终返回null,即使我做了人们推荐的stackoverflow的所有操作,android,bitmap,compression,Android,Bitmap,Compression,我觉得我什么都试过了。我想到的最后一件事是:我是否需要root来执行getDrawingCache?我想我不应该这样做,因为当我在玩它的时候,它已经对我起了作用,并且在onClick的另一个活动中尝试了它(尽管它只保存了按钮背景)。 GraphView是我的班级在画布上绘制图形。我没有忘记补充 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 我很抱歉发布了类似的问题

我觉得我什么都试过了。我想到的最后一件事是:我是否需要root来执行getDrawingCache?我想我不应该这样做,因为当我在玩它的时候,它已经对我起了作用,并且在onClick的另一个活动中尝试了它(尽管它只保存了按钮背景)。 GraphView是我的班级在画布上绘制图形。我没有忘记补充

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>       
我很抱歉发布了类似的问题(我之前已经发布过类似的问题,但问题仍然没有回答,可能是我解释得不够或者其他什么,所以这里有一个新的尝试)。这是我在学士学位论文中最后要完成的一件事。我需要在下周二之前把它准备好。在我的代码中,除此之外,其他一切都可以正常工作。如果你能帮忙,请提前谢谢

        GraphView graphView = new GraphView(this, y, "Dive Planner", horlabels, verlabels, GraphView.LINE, x, Pspotreba, pocetBodu, varovani);
    setContentView(graphView);




        graphView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        graphView.layout(0, 0, graphView.getMeasuredWidth(), graphView.getMeasuredHeight());

        graphView.setDrawingCacheEnabled(true);
        graphView.buildDrawingCache();
        Bitmap bm=Bitmap.createBitmap(graphView.getDrawingCache(true));
        //I have also tried Bitmap bm=graphView.getDrawingCache(true); and all the combinations (using/not using the code above)




        FileOutputStream fOut = null;

        try {   
                File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "DivePlanner" + File.separator);
                if(!f.exists()) f.mkdirs();
                File dive = new File(f, "Dive.png");

                fOut = new FileOutputStream(dive);
           }
        catch (Exception e) {
                Toast.makeText(this, "Error2", Toast.LENGTH_SHORT).show();
           }


        try {
                bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
                fOut.flush();
                fOut.close();
                Toast.makeText(this, "Ponor uložen", Toast.LENGTH_SHORT).show();
            } 
        catch (Exception e) 
            {
                Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
            }