qq_15838819 2016-10-15 07:10 采纳率: 0%
浏览 1135

求帮助 android Volley的BUG

今天程序莫名其妙崩溃
10-15 14:32:57.463: E/AndroidRuntime(16119): FATAL EXCEPTION: Thread-774
10-15 14:32:57.463: E/AndroidRuntime(16119): Process: com.cyber.testapp, PID: 16119
10-15 14:32:57.463: E/AndroidRuntime(16119): java.lang.NegativeArraySizeException: -374
10-15 14:32:57.463: E/AndroidRuntime(16119): at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:317)
10-15 14:32:57.463: E/AndroidRuntime(16119): at com.android.volley.toolbox.DiskBasedCache.get(DiskBasedCache.java:118)
10-15 14:32:57.463: E/AndroidRuntime(16119): at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:101)

上网查了说是Volley本身有问题 但是完全不知道该怎么处理
https://github.com/mcxiaoke/android-volley/commit/2f317deb8c9cfdf349a9a3b7a90207c2bf5649b7
这个网址根本看不懂是什么意思 是要修改Volley里面的代码么? 但是网上根本找不到源码啊。。。

  • 写回答

1条回答 默认 最新

  • C盘无限大 2016-10-15 09:13
    关注

    网上说的是修改volley包目录下com/android/volley/toolbox/DiskBasedCache.java文件,找到public synchronized Entry get(String key) 这个方法
    在catch中再加上NegativeArraySizeException的捕获

     @Override
        public synchronized Entry get(String key) {
            CacheHeader entry = mEntries.get(key);
            // if the entry does not exist, return.
            if (entry == null) {
                return null;
            }
    
            File file = getFileForKey(key);
            CountingInputStream cis = null;
            try {
                cis = new CountingInputStream(new FileInputStream(file));
                CacheHeader.readHeader(cis); // eat header
                byte[] data = streamToBytes(cis, (int) (file.length() - cis.bytesRead));
                return entry.toCacheEntry(data);
            } catch (IOException e) {
                VolleyLog.d("%s: %s", file.getAbsolutePath(), e.toString());
                remove(key);
                return null;
            }  
                    //就是加下面这段
                    catch (NegativeArraySizeException e) {
               VolleyLog.d("%s: %s", file.getAbsolutePath(), e.toString());
                remove(key);
                return null;
            }
                    finally {
                if (cis != null) {
                    try {
                        cis.close();
                    } catch (IOException ioe) {
                        return null;
                    }
                }
            }
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作