android - 调试时看不到变量值

标签 android android-studio android-debug

代码如下,我设置了一个断点来检查文件是否创建成功,但是在调试窗口中变量值是一个空字符串,如图所示,这是为什么?可能需要打开IDE的一些选项?

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        File file = new File(getFilesDir(), "img.png");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

enter image description here

android studio版本是3.1.4

已编辑: 现在这个问题严重影响了我的发展,我会这样阅读文件:

        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();//throw exception 
        }

但我可以看到该文件确实存在于我的应用程序私有(private)文件夹中,为什么会这样?我尝试在外部存储中写入和读取文件,但结果相同。

最佳答案

这是一个奇怪的问题。当我尝试您在我的测试应用程序中发布的代码时,我可以看到 getFilesDir() 的值。它向我指出了这可能是一个环境问题的方向。就我而言,我尝试在配置为 Nexus 6p 和 API 级别 23 的模拟器上进行检查。我建议尝试使用其他设备或具有您已有的不同配置的新模拟器。这可能是模拟器或设备错误。

关于android - 调试时看不到变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51977031/

相关文章:

android - ActivityThread.handleBindApplication 中的 NullPointerException

android - 未能找到 : com. android.support :appcompat-v7:22. 2.0

android - 具有自定义 View 的不同 packageNameSuffix

android - 在 Debug模式下自动授予运行时权限

android - 构建 apk 以调试和 Release模式,而无需每次更改 Android Google API key ?

android - 使用 adb 或 Eclipse 唤醒 Android(就在调试之前)?

android - 找不到兼容的目标

android - 在 android 中我如何传递 Arraylist<Float>

android - 删除 TextView 的背景

unit-testing - 在其自己的 JVM 中与每个测试类并行收集并运行所有 junit 测试(按类并行化,而不是按方法并行化)