How to solve the error: Exception in thread "AWT-EventQueue-0" java.lang.​IllegalArg​umentExcep​tion: Comparison method violates its general contract!

599 views (last 30 days)
Hello,
I started receiving an error in matlab, which prevents me to see the command window but does not prevent the code from executing. I attached all the error message below. I do not know why this is happening but I guess it started after I used "save" commands in the editor. I basically load data into the editor and then preprocess the data so that I can use them later, and I save the new data for future computations. Since when I started saving data, this problem has been initiated. Now, I can't stop matlab to produce this error every time I run any code. Can you please help me with this? I really appreciate that, thank you.
Original error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeHi(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.ArrayList.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at com.mathworks.widgets.grouptable.GroupingTableUtils.sortNonRecursively(GroupingTableUtils.java:296)
at com.mathworks.widgets.grouptable.RowListTransactionTarget.finishTransaction(RowListTransactionTarget.java:115)
at com.mathworks.widgets.grouptable.GroupingTableTransaction$1.run(GroupingTableTransaction.java:112)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
>>
Sincerely,
Irem Velibeyoglu
  4 Comments
Jaroslav Kautsky
Jaroslav Kautsky on 7 Jan 2019
Interestingly, I started to get same messages, many, many lines. However, I am using version '9.4.0.813654 (R2018a)' on a Linux-Mint notebook, with the -nodesktop option (command window only). I have no files with '0' in the filename in the current directory (as suggested below here). May be I should stop using java? Thank you ..
Omkar Tulankar
Omkar Tulankar on 23 Nov 2021
I was working on simscape multibody to define the motion of a .stp file imported into simulink.
Similar to above java related error , I am recieving following error:
Exception in thread "AWT-EventQueue-0": com.mathworks.physmod.sm.gui.core.exceptions.PmfException: Invalid camera position. The camera position and center are coincident.
at com.mathworks.physmod.sm.gui.gfx.viewer.OsgSceneViewer.fitView(Native Method)
at com.mathworks.physmod.sm.gui.gfx.viewer.OsgSceneViewer.fitView(OsgSceneViewer.java:498)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorPanel.loadGfxInTiledPane_(MechEditorPanel.java:1667)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorPanel.loadModelInternal_(MechEditorPanel.java:965)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorPanel.loadModel(MechEditorPanel.java:880)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorDTClient.openModel(MechEditorDTClient.java:956)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorDTClient.processDTClientCmdLineArgs(MechEditorDTClient.java:1547)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorDTClient.open(MechEditorDTClient.java:1416)
at com.mathworks.physmod.sm.gui.app.editor.MechEditorDTClient.open(MechEditorDTClient.java:1060)
at com.mathworks.physmod.sm.gui.app.editor.NativeMechEditorDTClient$1.run(NativeMechEditorDTClient.java:47)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Suprisingly my other models are working fine ,I am not able to figure out why the above error is being generated

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Apr 2016
This is related to a Java issue, for which there is information at http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7075600
It looks to me as if your choices are:
  • downgrade java versions
  • downgrade to a version of MS Windows is supported by your R2014a
  • upgrade to a version of MATLAB that is supported on Windows 10
  • try to get Mathworks to patch a 2-year old release.

More Answers (5)

Jim Meyer
Jim Meyer on 10 May 2016
Edited: Jim Meyer on 10 May 2016
I just started getting this error when switching to a specific folder within Matlab. I tracked it down to having added a file with a similar name to a file that already existed in the folder. The file names were "TFH114H.TST" and "TFH0114H.TST". Windows treats them as separate files, but it seems Java is somehow comparing them, treating the numeric characters in the middle as a combined number, ignoring the leading zero in the one file name, and somehow concluding they are the same file and so throwing the error? Adding an extra zero to the second name to make it "TFH00114H.TST" keeps the error, so I think my theory is correct. Renaming the files so the numeric characters do not resolve to the same number cures the problem.
  4 Comments
James Bell
James Bell on 20 Oct 2016
This fixed the same problem for me, too, using R2014b. It seems this version of Matlab doesn't recognise leading zeros in filenames. Great find Jim!

Sign in to comment.


Vahab Youssofzadeh
Vahab Youssofzadeh on 3 Apr 2018
restoredefaultpath is the solution
  3 Comments
Michael McDermott
Michael McDermott on 1 May 2020
Thank you! This totally worked after I ran it once... Then I could take it out and still run the code, with the Java problem gone seemingly for now.

Sign in to comment.


Pablo Morcillo Pallarés
Pablo Morcillo Pallarés on 19 Sep 2018
I was also having the same issue, but i solved it in a different way:
i was extracting the maximum value from a table, and the output of that "max" function was giving me a "single" value that later i would use in the axis of a figure. By changing it to "double" the error does not appears again:
from this:
max_=max(Y);
To this:
max_=double(max(Y));

micholeodon
micholeodon on 9 Jan 2021
My answer is not a universal solution but it might be a case for somebody.
I also started to have this error when I accidentally opened a nii.gz (file with the MRI data) file in the Editor. I closed MATLAB and run again - the problem persisted.
Finally problem was solved when I closed a tab in the editor with that nii.gz file.
  1 Comment
Walter Roberson
Walter Roberson on 9 Jan 2021
Ah, that makes some sense. The editor needs java memory for open files, so if you open a large enough file you can run into java problems. Adjusting the java memory preference can postpone this kind of issue, but there will always be files large enough to trigger the problem.

Sign in to comment.


Xin Zhao
Xin Zhao on 16 May 2021
install java solves the problem for me

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!