嗨,下面是我比较器的比较方法.我不确定是什么问题.我在堆栈溢出时查找了其他类似的标题问题和答案,但不确定我的方法有什么问题,但我不断得到java.lang.IllegalArgumentException:比较方法违反了它的一般合同!
任何帮助将不胜感激
public int compare(Node o1, Node o2)
{
HashMap<Integer,Integer> childMap = orderMap.get(parentID);
if(childMap != null && childMap.containsKey(o1.getID()) &&
childMap.containsKey(o2.getID()))
{
int order1 = childMap.get(o1.getID());
int order2 = childMap.get(o2.getID());
if(order1<order2)
return -1;
else if(order1>order2)
return 1;
else
return 0;
}
else
return 0;
}
Run Code Online (Sandbox Code Playgroud)
添加我得到的例外
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:747)
at java.util.TimSort.mergeAt(TimSort.java:483)
at java.util.TimSort.mergeCollapse(TimSort.java:410)
at java.util.TimSort.sort(TimSort.java:214)
at java.util.TimSort.sort(TimSort.java:173)
at java.util.Arrays.sort(Arrays.java:659)
at java.util.Collections.sort(Collections.java:217)
Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,我想显示一系列YouTube视频.但是我想让列表显示带有其他信息的视频标题,但也会显示视频的缩略图,就像我们去www.youtube.com时一样
有人可以帮我吗?如何显示视频网址的缩略图?
我试图在屏幕中央显示进度条,但它不会显示在中心.下面是我的布局.我在这做错了什么?基本上这是一个布局,以显示图像和Android画廊小部件在上面.当用户点击缩略图时,我正在从网络加载图像,我想在加载图像时显示进度对话框.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/container" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="top" />
<ImageView android:id="@+id/actualimage" android:scaleType="fitCenter"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="gone" android:layout_gravity="center_vertical|center_horizontal|center"
android:adjustViewBounds="true" />
<ProgressBar android:id="@+android:id/progress_small1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:visibility="visible" android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)