簡體   English   中英

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

[英]@@@ ABORTING: INVALID HEAP ADDRESS IN 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();
    }

Path對象不可序列化。 我相信這是導致錯誤的原因,為了解決這個問題,我創建了一個自定義數據結構,該結構實現可序列化以保存每個路徑的指令,然后從該路徑構造我的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM