调试异步任务时,在Android中聊斋志异调试器行为 [英] Strange debugger behaviour in Android studio when debugging an Async task

查看:223
本文介绍了调试异步任务时,在Android中聊斋志异调试器行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使用Android Studio的断点,以便调试我的code,但他们给了我非常怪异的行为。比如我试图调试下面的代码片段:

I've been trying to use the Android Studio breakpoints in order to debug my code, but they are giving me extremely weird behaviour. For example I'm trying to debug the following snippet:

new AsyncTask<Void, Void, Exception>() {
    @Override
    protected Exception doInBackground(Void... params) {
        try {
            Assets assets = new Assets(MainActivity.this);
            File assetDir = assets.syncAssets();
            setupRecognizer(assetDir);
        } catch (IOException e) {
            return e;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Exception result) {
        if (result != null) {
            ((TextView) findViewById(R.id.textView))
                    .setText("Failed to init recognizer " + result);
        } else {
            switchSearch(KWS_SEARCH);
        }
    }
}.execute();

我把一个断点就行了。

I put a breakpoint on the line

Assets assets = new Assets(MainActivity.this);

然后我说:成步。这需要我去一个反编译类文件和下面的code片断:

And then I say "Step into". This takes me to a "decompiled class file" and the following code snippet:

public Assets(Context context) throws IOException {
    File appDir = context.getExternalFilesDir((String)null);
    if(null == appDir) {
        throw new IOException("cannot get external files dir, external storage state is " + Environment.getExternalStorageState());
    } else {
        this.externalDir = new File(appDir, "sync");
        this.assetManager = context.getAssets();
    }
}

这是完全预期的和合理的。在此之后我尝试步入行

Which is completely expected and reasonable. After this I try to step into the line

File appDir = context.getExternalFilesDir((String)null);

然后事情就变得很奇怪。首先,我得到带到一个新的文件,我降落在两种方法之间的空行。当我尝试步入空行我得到反弹到执行已经在另一种方法的右大括号暂停另一个文件。然后,我踏入了大括号,我得到带到另一个空行中的另一个文件两种方法之间。当我踏进了,我得到带到第二天线,这是一个简单的 @override 注释。走进那带我到if语句的花括号中的另一个文件。

And then things get really weird. First I get taken to a new file where I land on a blank line in between two methods. When I try to step into the blank line I get bounced to another file where execution has halted at the closing curly brace of another method. Then I step into that curly brace and I get taken to another blank line between two methods in another file. When I step into that, I get taken to the very next line, which is simply an @override annotation. Stepping into that takes me to the closing curly brace of an if statement in yet another file.

这怪异的行为仍在继续和我无法理解它。在一个点上调试器甚至似乎注释的中间暂停执行!这怎么可能呢?有谁知道为什么发生这种情况?是否有东西做,我调试的AsyncTask的事实?

This weird behaviour continues on and on and I can't make sense of it. At one point the debugger even seems to pause execution in the middle of a comment! How is that even possible? Does anyone know why this is happening? Does it have something to do with the fact that I am debugging an AsyncTask?

(请注意,我已经重复了这个调试过程四次,一直与每一次相同的奇怪的行为psented $ P $)

(Note that I have repeated this debugging process four times and been presented with the same strange behaviour every time)

推荐答案

是不是在调试一个问题。当在空白或者注释调试暂停只是所提供的原始源$ C ​​$ C级和源不同步或不在同一版本。

Is not a problem in Debug. When Debug pause in blank space or comment is just that the original source code class and the source provided is not synchronized or is not at the same version.

编辑:

让我用一个例子说明你。你已经第三方库XXX-1.1.jar,你想这个库的code里面调试,所以你用Google搜索和查找源这瓶XXX-1.1-source.jar。但是,对于XXX-1.1-source.jar的某种原因,开发商打包这个源2小时后创建XXX-1.1.jar,他在要调试等等一些类的开头添加一些评论,在这一点上,当你调试XXX -1.1.jar利用XXX-1.1-source.jar源$ C ​​$ C提供的code不完全匹配。

Let me explain you with an example. You've a third party library xxx-1.1.jar, and you want to debug inside code of this library so you googled and find the source xxx-1.1-source.jar of this jar. But for some reason developer of xxx-1.1-source.jar packaged this source 2 hours after create xxx-1.1.jar and he add some comment at the beginning of some class that you want to debug so, at this point when you debug xxx-1.1.jar using the code provided by xxx-1.1-source.jar the source code don't match exactly.

希望它帮助!

这篇关于调试异步任务时,在Android中聊斋志异调试器行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆