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 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试