“尝试捕捉”完全被代码省略

发布于 2024-12-11 06:47:46 字数 846 浏览 0 评论 0原文

我有这段代码,用于截图。我在我的一个应用程序中安装并运行得非常好,我将其用作“草稿”。

然而,现在我将代码复制到原来的项目中,似乎代码从未真正进入“尝试”部分。这有点令人困惑,因为它在其他示例应用程序上仍然运行良好,但在这里却不然。仅供您参考,也没有发布任何错误。这里发生了什么?

public void getScreen()
{
    View table = findViewById(R.id.TransactionLog);
    table.setDrawingCacheEnabled(true);

    table.buildDrawingCache(true);

    Bitmap bitmap = Bitmap.createBitmap(table.getDrawingCache());
    table.setDrawingCacheEnabled(false); // Clear drawing cache

    File doc = new File( Environment.getExternalStorageDirectory() + "TransactionHistory.png");

    try
    {
        doc.createNewFile();
        FileOutputStream ostream = new FileOutputStream(doc);
        bitmap.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
        sendmail();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

I have this code which is meant to take screenshots. I had it up and running perfectly fine in one of my apps which I was using as a "rough draft".

However, now that I copied the code into my original project, it seems like the code never really enters the "try" portion. This is kind of confusing since it is still running fine on the other sample app but not here. And just for your information, no errors are being posted either. What is happening here?

public void getScreen()
{
    View table = findViewById(R.id.TransactionLog);
    table.setDrawingCacheEnabled(true);

    table.buildDrawingCache(true);

    Bitmap bitmap = Bitmap.createBitmap(table.getDrawingCache());
    table.setDrawingCacheEnabled(false); // Clear drawing cache

    File doc = new File( Environment.getExternalStorageDirectory() + "TransactionHistory.png");

    try
    {
        doc.createNewFile();
        FileOutputStream ostream = new FileOutputStream(doc);
        bitmap.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
        sendmail();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷…雨湿花 2024-12-18 06:47:46

以及提出的所有其他建议一样,它可能会抛出异常:

File doc = new File.....

在这种情况下,它永远不会进入您的 try/catch。将一些日志记录语句或调试断点放在方法的开头以及调用该方法的任何位置。

As well as all the other suggestions made, it could be throwing an exception on the line:

File doc = new File.....

in which case it will never enter your try/catch. Put some logging statements or debugging breakpoints at the beginning of the method and anywhere the method is being called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文