I get the following exception when running this code
private static String getClipboard() {
try {
return (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
} catch (IOException | UnsupportedFlavorException e) {
System.exit(-1);
return "";
}
}
Exception "java.lang.ClassNotFoundException: com/intellij/codeInsight/editorActions/FoldingData"while constructing DataFlavor for: application/x-java-jvm-local-objectref; class=com.intellij.codeInsight.editorActions.FoldingData
Exception "java.lang.ClassNotFoundException: com/intellij/codeInsight/editorActions/FoldingData"while constructing DataFlavor for: application/x-java-jvm-local-objectref; class=com.intellij.codeInsight.editorActions.FoldingData
Exception "java.lang.ClassNotFoundException: com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData"while constructing DataFlavor for: application/x-java-serialized-object; class=com.intellij.openapi.editor.impl.EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData
Exception "java.lang.ClassNotFoundException: com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData"while constructing DataFlavor for: application/x-java-serialized-object; class=com.intellij.openapi.editor.impl.EditorCopyPasteHelperImpl$CopyPasteOptionsTransferableData
I haven't found a clear solution to completely solve this. Someone suggested to print every error in a file, but this wouldn't solve the problem and would "hide" it instead. Any idea on how to prevent that exception from happening?
You should always check what the available clipboard formats are before accessing, as it may not always contain a
String. You can do this with:This will print what formats are available:
It is never a good plan to slip
System.exit()into any handler - remove. In theory the clipboard could be changed by another app between checking so you need your exception handler to return "" or throw it as your own exception type.