【问题标题】:uses unchecked or unsafe operations, Recompile with -Xlint:unchecked for details [duplicate]使用未经检查或不安全的操作,使用 -Xlint 重新编译:未检查详细信息 [重复]
【发布时间】:2019-09-02 01:54:47
【问题描述】:

我有一个应用程序,当我尝试运行它时显示错误:

使用未经检查或不安全的操作。 使用 -Xlint:unchecked 重新编译以获取详细信息。

如果有人知道为什么我该如何解决这个错误?拜托,我需要帮助来解决这个问题。

.................................................. ……………………………………………………………………………………………………………………………………………… ......................................

@QuranPageScope
public class AyahTrackerPresenter implements AyahTracker,
    Presenter<AyahTrackerPresenter.AyahInteractionHandler> {
  private AyahTrackerItem[] items;
  private HighlightInfo pendingHighlightInfo;

  @Inject
  public AyahTrackerPresenter() {
    this.items = new AyahTrackerItem[0];
  }

  public void setPageBounds(int page, RectF bounds) {
    for (AyahTrackerItem item : items) {
      item.onSetPageBounds(page, bounds);
    }
  }

  public void setAyahCoordinates(int page, Map<String, List<AyahBounds>> coordinates) {
    for (AyahTrackerItem item : items) {
      item.onSetAyahCoordinates(page, coordinates);
    }

    if (pendingHighlightInfo != null && !coordinates.isEmpty()) {
      highlightAyah(pendingHighlightInfo.sura, pendingHighlightInfo.ayah,
          pendingHighlightInfo.highlightType, pendingHighlightInfo.scrollToAyah);
    }
  }

  public void setAyahBookmarks(List<Bookmark> bookmarks) {
    for (AyahTrackerItem item : items) {
      item.onSetAyahBookmarks(bookmarks);
    }
  }

  @Override
  public void highlightAyah(int sura, int ayah, HighlightType type, boolean scrollToAyah) {
    boolean handled = false;
    int page = items.length == 1 ? items[0].page : QuranInfo.getPageFromSuraAyah(sura, ayah);
    for (AyahTrackerItem item : items) {
      handled = handled || item.onHighlightAyah(page, sura, ayah, type, scrollToAyah);
    }

    if (!handled) {
      pendingHighlightInfo = new HighlightInfo(sura, ayah, type, scrollToAyah);
    } else {
      pendingHighlightInfo = null;
    }
  }

  @Override
  public void highlightAyat(int page, Set<String> ayahKeys, HighlightType type) {
    for (AyahTrackerItem item : items) {
      item.onHighlightAyat(page, ayahKeys, type);
    }
  }

  @Override
  public void unHighlightAyah(int sura, int ayah, HighlightType type) {
    int page = items.length == 1 ? items[0].page : QuranInfo.getPageFromSuraAyah(sura, ayah);
    for (AyahTrackerItem item : items) {
      item.onUnHighlightAyah(page, sura, ayah, type);
    }
  }

  @Override
  public void unHighlightAyahs(HighlightType type) {
    for (AyahTrackerItem item : items) {
      item.onUnHighlightAyahType(type);
    }
  }

  @Override
  public AyahToolBar.AyahToolBarPosition getToolBarPosition(int sura, int ayah,
                                                            int toolBarWidth, int toolBarHeight) {
    int page = items.length == 1 ? items[0].page : QuranInfo.getPageFromSuraAyah(sura, ayah);
    for (AyahTrackerItem item : items) {
      AyahToolBar.AyahToolBarPosition position =
          item.getToolBarPosition(page, sura, ayah, toolBarWidth, toolBarHeight);
      if (position != null) {
        return position;
      }
    }
    return null;
  }

  public boolean handleTouchEvent(Activity activity, MotionEvent event,
                                  AyahSelectedListener.EventType eventType, int page,
                                  AyahSelectedListener ayahSelectedListener,
                                  boolean ayahCoordinatesError) {
    if (eventType == AyahSelectedListener.EventType.DOUBLE_TAP) {
      unHighlightAyahs(HighlightType.SELECTION);
    } else if (ayahSelectedListener.isListeningForAyahSelection(eventType)) {
      if (ayahCoordinatesError) {
        checkCoordinateData(activity);
      } else {
        handlePress(event, eventType, page, ayahSelectedListener);
      }
      return true;
    }
    return ayahSelectedListener.onClick(eventType);
  }

  private void handlePress(MotionEvent ev, AyahSelectedListener.EventType eventType, int page,
                           AyahSelectedListener ayahSelectedListener) {
    SuraAyah result = getAyahForPosition(page, ev.getX(), ev.getY());
    if (result != null && ayahSelectedListener != null) {
      ayahSelectedListener.onAyahSelected(eventType, result, this);
    }
  }

  @Nullable
  private SuraAyah getAyahForPosition(int page, float x, float y) {
    for (AyahTrackerItem item : items) {
      SuraAyah ayah = item.getAyahForPosition(page, x, y);
      if (ayah != null) {
        return ayah;
      }
    }
    return null;
  }

  private void checkCoordinateData(Activity activity) {
    if (activity instanceof PagerActivity &&
        (!QuranFileUtils.haveAyaPositionFile(activity) ||
            !QuranFileUtils.hasArabicSearchDatabase(activity))) {
      PagerActivity pagerActivity = (PagerActivity) activity;
      pagerActivity.showGetRequiredFilesDialog();
    }
  }

  @Override
  public void bind(AyahInteractionHandler interactionHandler) {
    this.items = interactionHandler.getAyahTrackerItems();
  }

  @Override
  public void unbind(AyahInteractionHandler interactionHandler) {
    this.items = new AyahTrackerItem[0];
  }

  public interface AyahInteractionHandler {
    AyahTrackerItem[] getAyahTrackerItems();
  }
}

【问题讨论】:

    标签: java android android-studio kotlin


    【解决方案1】:

    当编译器通常无法确保类型安全时会出现此警告。

    如果您按照它的建议进行操作并使用-Xlint:unchecked 开关重新编译,它将为您提供更详细的信息。

    未经检查的强制转换可能会导致此警告。

    如果您认为您的代码是正确的,那么只需通过使用来抑制此警告

    @SuppressWarnings("unchecked")
    public void yourfunction() {
        //you code that causes this warning
    }
    

    【讨论】:

    • 我的荣幸。谢谢。
    • hmmmm 我有太多错误你能帮帮我吗?
    猜你喜欢
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    相关资源
    最近更新 更多