【问题标题】:Android error incomparable types: Object and intAndroid错误无法比拟的类型:Object和int
【发布时间】:2016-03-29 22:37:07
【问题描述】:

我正在导入源代码,并且在两个代码位置出现此错误:

错误:(86, 60) 错误:无法比较的类型:Object 和 int

if (selectedPhotos.containsKey(photoEntry.imageId)) {
  selectedPhotos.remove(photoEntry.imageId);
  v.setChecked(false, true);
  photoEntry.imagePath = null;
  photoEntry.thumbPath = null;
  v.setPhotoEntry(photoEntry, v.getTag() == MediaController.allPhotosAlbumEntry.photos.size() - 1);
                                   // ^-here-^
} else {
  selectedPhotos.put(photoEntry.imageId, photoEntry);
  v.setChecked(true, true);

还有这个:

if (passwordFrameLayout.getTag() != 0) {
//                               ^Here
  t = (Integer) passwordFrameLayout.getTag();
}

我应该对这些进行哪些更改?

  • 我在 Stack 中进行了搜索,但无法修复它们。我是这方面的新手,请帮忙。

  • 顺便说一句,我正在使用 Android Studio Last Version!

  • 我正在开发主要的Telegram source,没有任何变化。

并获取标签功能:

@ViewDebug.ExportedProperty
  public Object getTag() {
    return mTag;
  }

在android-23/android/view/View.java中

【问题讨论】:

  • getTag() 的类型是什么?显然不是整数。
  • @Eran 编辑并添加。
  • 好吧,知道它是一个对象并没有多大帮助。它返回的实际(特定)类型是什么?
  • @Eran 输出类型为FrameLayout passwordFrameLayout
  • 那你为什么要把它和一个数字比较呢?你期望发生什么?

标签: java android android-studio telegram


【解决方案1】:
if (passwordFrameLayout.getTag() instanceOf Integer && (Integer)passwordFrameLayout.getTag() != 0) {
//         
    t = (Integer) passwordFrameLayout.getTag();
}

应该做的伎俩。 getTag()返回一个Object,你必须

  • 首先确保它是一个整数
  • 将其转换为整数

将其与另一个整数进行比较

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 2023-03-15
    • 2019-02-24
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多