General questions

Answered

Internal error while using editor.import_()

Hi, it is me from the "Line Break Detect" topic

After run what you told me, i got this error 

image

but when i run it in debug mode, it seems to be fine 

this is my code:

  

private void bulletAdding (@NotNull Editor editor, int kindHead) {
        String exportResult = null;

        try {
            exportResult = editor.export_(null, MimeType.TEXT);
        } catch (IOException e) {
            //e.printStackTrace();
        }
        String export = null;
        if (exportResult != null) {
            if (kindHead == 1) {
                export = exportResult.replace("\n", "\n•");
                export = "•" + export;
            }
            if (kindHead == 2) {
                String[] replaced;
                replaced = exportResult.split("");
                int count = 1;
                int i = 0;

                while (i < replaced.length) {
                    if (replaced[i].equals("\n")) {
                        count++;
                        replaced[i] = "\n" + count + ".";
                    }
                    i++;
                }
                export = "1.";
                i = 0;
                while (i < replaced.length) {

                    if (!replaced[i].equals("") && !replaced[i].equals(" ")) {
                        export = export + replaced[i];
                    }
                    i++;

                }
            }
        }
        editor.clear();
        editor.import_(MimeType.TEXT, export, null);

 

can you help me with this?



Best Answer

Dear Tung Bach Nguyen Le,



By checking your code, I suspect this might be due to the fact that your editor has still its part in memory.


So clearing the editor is not enough, you should close the part and create a new one before importing the updated text.

Suppose your editor package has a single 'Text' content part and your package is named contentPackage, this could be done by inserting following code block after editor clear and before editor import:

contentPart = contentPackage.getPart(0);

if (contentPart != null)
{
contentPart.close();
contentPart = null;
}
editor.setPart(null);

contentPart = contentPackage.createPart("Text");
editor.setPart(contentPart);



Best regards,


Gwenaëlle


1 Comment

Answer

Dear Tung Bach Nguyen Le,



By checking your code, I suspect this might be due to the fact that your editor has still its part in memory.


So clearing the editor is not enough, you should close the part and create a new one before importing the updated text.

Suppose your editor package has a single 'Text' content part and your package is named contentPackage, this could be done by inserting following code block after editor clear and before editor import:

contentPart = contentPackage.getPart(0);

if (contentPart != null)
{
contentPart.close();
contentPart = null;
}
editor.setPart(null);

contentPart = contentPackage.createPart("Text");
editor.setPart(contentPart);



Best regards,


Gwenaëlle