gpt4 book ai didi

java - Android 9.0 中的 ArrayIndexOutOfBoundsException

转载 作者:行者123 更新时间:2023-12-02 01:36:12 24 4
gpt4 key购买 nike

我仅在 Android 9.0 的生产中遇到奇怪的问题,该应用程序在生产中运行了很长时间,并且此问题从 Android 9.0 开始

Process: com.ae.paris10, PID: 18804 java.lang.ArrayIndexOutOfBoundsException: length=984; regionStart=0; regionLength=1024
at java.util.Arrays.checkOffsetAndCount(Arrays.java:1719)
at libcore.io.IoBridge.write(IoBridge.java:487)
at java.io.FileOutputStream.write(FileOutputStream.java:186)

   private void copyStyleWithNewTilesPath() throws IOException {

InputStream myinput = getContext()
.getAssets().open("styleParis.json");


String outfilename = "/data/data/" + Config.APPLICATION_ID + "/databases/styleParis.json";


OutputStream myoutput = new FileOutputStream(outfilename);

byte[] buffer = new byte[1024];
int length;
while ((length = myinput.read(buffer)) > 0) {

String str = new String(buffer, "UTF-8");

if (str.contains("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf")) {
buffer = str.replace("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf", "file://" + obbPath + "/{z}/{x}/{y}.pbf").getBytes("UTF-8");
}

myoutput.write(buffer, 0, length); <<--- EXCEPTION HERE <<-----------
}

//Close the streams
myoutput.flush();
myoutput.close();
myinput.close();
}

我不太明白发生了什么,因为 FileOutputStream 是 Java 和 Android 框架。

有人有什么想法吗?

最佳答案

我认为这会解决您的问题:

if (str.contains("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf"))
myoutput.write(str.replace("file://mnt/obb/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/{z}/{x}/{y}.pbf", "file://" + obbPath + "/{z}/{x}/{y}.pbf").getBytes("UTF-8"));
else
myoutput.write(buffer, 0, length);

关于java - Android 9.0 中的 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55229874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com