有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java@@正在中止:dlfree addr=0x00000156中的堆地址无效

当我的设备旋转时,我已经开始尝试在视图中保留一些数据。由于在一段时间后实施此操作,我的应用程序将因以下错误而崩溃:

@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x00000156
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 20787 (FinalizerDaemon)

每次尝试重新打开应用程序时,应用程序崩溃后,我会立即收到相同的错误,直到卸载应用程序

有人知道是什么导致了这个错误吗

以下是我用来保存数据的代码:

onDestory()

    System.out.println("Saving");
    ArrayList<Path> strokes = paintCanvas.strokes;
    ArrayList<Integer> colors = paintCanvas.colors;
    SharedPreferences settings = getSharedPreferences("colors", MODE_PRIVATE);
    settings.unregisterOnSharedPreferenceChangeListener(listener);



    /**Write Colors**/
    try
    {
        FileOutputStream os = openFileOutput("drawing.dat", MODE_PRIVATE);
        ObjectOutputStream output = new ObjectOutputStream(os);
        output.writeObject(colors);
        output.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    /**Write Paths**/
    try
    {

        Gson gson = new Gson();

        File file = getFileStreamPath("paths.txt");
        FileWriter writer = new FileWriter(file);
        BufferedWriter output = new BufferedWriter(writer);
        for(Path p : strokes)
        {
            String s = gson.toJson(p);
            s = s + "\n";
            output.write(s);
        }

        output.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        //System.out.println(e.getMessage());
    }

onCreate():

    //Try Load here!
    /**Read Colors**/
    try
    {
        ArrayList<Integer> colors;
        ArrayList<Path> strokes;
        FileInputStream ins = openFileInput("drawing.dat");
        ObjectInputStream reader = new ObjectInputStream(ins);
        colors = (ArrayList<Integer>)reader.readObject();

        paintCanvas.colors = colors;
        System.out.println("Colors Loaded");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    /**Read Paths**/
    try
    {
        FileInputStream fis = openFileInput("paths.txt");
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader bufferedReader = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();
        String line;
        Gson gson = new Gson();

        ArrayList<Path> paths = new ArrayList<Path>();
        while ((line = bufferedReader.readLine()) != null)
        {   
            paths.add(gson.fromJson(line,Path.class));
        }


        paintCanvas.strokes = paths;
        paintCanvas.currentStroke = paintCanvas.strokes.size() - 1;
        System.out.println("Paths Loaded");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

共 (1) 个答案

  1. # 1 楼答案

    Path对象不可序列化。我相信这是导致错误的原因,为了解决这个问题,我创建了一个自定义数据结构,它实现了serializable来保存每个路径的指令,然后用它构建了我的路径