无限递归导致StackOverflowError

先贴上这一段错误代码:

/**
 * Created by wangke on 2017-07-20.
 * 上传文件到七牛云的工具类
 */

public  class UpLoadHelper {

    private static final String accessKey = "KXLzuFCOxgNar5whqU3-0bmrH6rTHOqaidcohRes1";
    private static final String secretKey = "aiw1aAh-dwA9k6nkWAQLExy2Taz9cE1nFYA_01WY1";
    private CompletionListener mCompletionListener = null;


    /**
     * 上传头像
     *
     * @param path
     */
    public void upLoadAveter(String path, String key, CompletionListener completionListener) {

        this.mCompletionListener = completionListener;

        Auth auth = Auth.create(accessKey, secretKey);
        //上传凭证
        String uploadToken = auth.uploadToken("kangyuanmilk", "/aveter");
        UploadManager uploadManager = UpLoadManagerFactory.getInstance();

        uploadManager.put(path, key, uploadToken, new UpCompletionHandler() {
            //上传进度的回调
            @Override
            public void complete(String key, ResponseInfo info, JSONObject response) {

                if (mCompletionListener != null) {
                    complete(key, info, response);
                }

            }
        }, null);


    }


    public interface CompletionListener {

        public void complete(String key, ResponseInfo info, JSONObject response);
    }

}

在使用uploadManager.put方法上传图片的时候需要添加一个回调来通知当前上传文件的进度等信息,为了简化上传代码于是稍微封装了一下,因为涉及到了一个回调所以就写了一个接口用于将当前的上传状态通知外界,不幸的是我自己写的那个回调方法与uploadManager.put方法中的回调方法的命名是相同的,这也就导致了后面在调用的时候就变成了递归调用,一直到后面栈溢出。

报错信息:

07-20 16:03:00.224 7475-7475/com.merpyzf.kangyuanmilk E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.merpyzf.kangyuanmilk, PID: 7475
                                                                        java.lang.StackOverflowError: stack size 8MB

你可能感兴趣的:(开发中遇到的bug)