开发者社区 问答 正文

Android 开发中遇到的问题?报错

一个安卓项目运行在5.0的手机上就会报错,以下是错误日志

下面是对应提示错误的类的代码

/*
 * Copyright (c) 2013. wyouflf (wyouflf@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.c1tech.dress.bitmap.xutils.util.core;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Author: wyouflf
 * Date: 13-8-1
 * Time: 上午11:25
 */
public class KeyExpiryMap<K, V> extends ConcurrentHashMap<K, Long> {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private static final int DEFAULT_CONCURRENCY_LEVEL = 16;

    public KeyExpiryMap(int initialCapacity, float loadFactor, int concurrencyLevel) {
        super(initialCapacity, loadFactor, concurrencyLevel);
    }

    public KeyExpiryMap(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor, DEFAULT_CONCURRENCY_LEVEL);
    }

    public KeyExpiryMap(int initialCapacity) {
        super(initialCapacity);
    }

    public KeyExpiryMap() {
        super();
    }

    @Override
    public synchronized Long get(Object key) {
        if (this.containsKey(key)) {
            return super.get(key);
        } else {
            return null;
        }
    }

    @Override
    public synchronized Long put(K key, Long expiryTimestamp) {
        if (this.containsKey(key)) {
            this.remove(key);
        }
        return super.put(key, expiryTimestamp);
    }

    @Override
    public synchronized boolean containsKey(Object key) {
        boolean result = false;
        if (super.containsKey(key)) {
            if (System.currentTimeMillis() < super.get(key)) {
                result = true;
            } else {
                this.remove(key);
            }
        }
        return result;
    }

    @Override
    public synchronized Long remove(Object key) {
        return super.remove(key);
    }

    @Override
    public synchronized void clear() {
        super.clear();
    }
}



展开
收起
爱吃鱼的程序员 2020-06-10 11:25:11 653 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    代码出现递归且层级太多了,看了,containsKey里,你调用了父类,而父类的判断你应该去看看源码,里面调用了get了,而你又在get里调用了containsKey。


    你错误日志完整copy一下在发过来,截图里的内容都是虚拟机运行后出错的地方看这个又没有大用,而且你代码里super好多,父类谁知道你怎么写的
    2020-06-10 11:25:28
    赞同 展开评论