广告加载错误

如果广告加载失败,则一定会调用回调以此来提供 LoadAdError 对象。

对于 an AdView,系统将调用以下内容:

以下代码段说明了广告加载失败时可用的信息:

Java

@Override
public void onAdFailedToLoad(LoadAdError error) {
  // Gets the domain from which the error came.
  String errorDomain = error.getDomain();
  // Gets the error code. See
  // https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#constant-summary
  // for a list of possible codes.
  int errorCode = error.getCode();
  // Gets an error message.

  // For example "Account not approved yet". See
  // https://support.google.com/admob/answer/9905175 for explanations of
  // common errors.

  String errorMessage = error.getMessage();
  // Gets the cause of the error, if available.
  AdError cause = error.getCause();
  // All of this information is available via the error's toString() method.
  Log.d("Ads", error.toString());
}

Kotlin

override fun onAdFailedToLoad(error: LoadAdError) {
    // Gets the domain from which the error came.
    val errorDomain = error.domain
    // Gets the error code. See
    // https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#constant-summary
    // for a list of possible codes.
    val errorCode = error.code
    // Gets an error message.

    // For example "Account not approved yet". See
    // https://support.google.com/admob/answer/9905175 for explanations of
    // common errors.

    val errorMessage = error.message
    // Gets the cause of the error, if available.
    val cause = error.cause
    // All of this information is available via the error's toString() method.
    Log.d("Ads", error.toString())
}

此信息可用于更准确地确定导致广告加载失败的原因。 特别是,对于网域 MobileAds.ERROR_DOMAIN 下的错误,消息 的更多详细说明可在此帮助中心文章中查看,还能了解解决问题可以采取的措施。