Clear Filters
Clear Filters

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

805 views (last 30 days)
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(
at com.mathworks.widgets.grouptable.RowListTransactionTarget.finishTransaction(
at com.mathworks.widgets.grouptable.GroupingTableTransaction$
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$ Source)
at java.awt.EventQueue$ Source)
at Method)
at$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 Source)
Irem Velibeyoglu
Jaroslav Kautsky
Jaroslav Kautsky on 7 Jan 2019
Interestingly, I started to get same messages, many, many lines. However, I am using version ' (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": Invalid camera position. The camera position and center are coincident.
at Method)
at java.awt.event.InvocationEvent.dispatch(
at java.awt.EventQueue.dispatchEventImpl(
at java.awt.EventQueue.access$500(
at java.awt.EventQueue$
at java.awt.EventQueue$
at Method)
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
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
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.
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
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:
To this:

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


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


Community Treasure Hunt

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

Start Hunting!