如果廣告無法載入,系統會呼叫回呼來提供 LoadAdError 物件。
如果是 AdManagerAdView,系統會呼叫下列項目:
Kotlin
fun onAdFailedToLoad(error: LoadAdError)
Java
public void onAdFailedToLoad(LoadAdError adError);
以下範例列出廣告無法載入時可參閱的資訊:
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/admob/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 additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // information.
  val responseInfo = error.responseInfo
  // Gets the cause of the error, if available.
  val cause = error.cause
  // All of this information is available using the error's toString() method.
  Log.d("Ads", error.toString())
}Java
@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
  // Gets the domain from which the error came.
  String errorDomain = adError.getDomain();
  // Gets the error code. See
  // https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdRequest#constant-summary
  // for a list of possible codes.
  int errorCode = adError.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 = adError.getMessage();
  // Gets additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // information.
  ResponseInfo responseInfo = adError.getResponseInfo();
  // Gets the cause of the error, if available.
  AdError cause = adError.getCause();
  // All of this information is available using the error's toString() method.
  Log.d("Ads", adError.toString());
}偵錯常見的錯誤記錄訊息
在 Google Mobile Ads SDK 23.5.0 版中,詳細記錄功能已獲得提升,可納入廣告無法載入位置的堆疊追蹤記錄。這些訊息並非指出當機,而是識別錯誤的獨特來源。下表列出常見的錯誤記錄、說明和建議的解決方法:
| 錯誤記錄 | 說明 | 建議採取的行動 | 
|---|---|---|
| com.google.android.gms.ads.nonagon.render.cp: * | 廣告伺服器未傳回廣告,或未傳回任何中介服務廣告來源供請求。 | 如要進一步瞭解如何排解沒有填滿的問題,請參閱「 排解未填滿的曝光次數」。 | 
| com.google.android.gms.ads.nonagon.render.e: * | 中介服務刊登序列中的所有廣告來源都無法載入。特定錯誤代表上次失敗的廣告來源。 | 如要進一步瞭解如何記錄各中介服務廣告來源的失敗原因,請參閱「 回應資訊」。 | 
| com.google.android.gms.ads.internal.util.*: Unable to obtain a JavascriptEngine. | 廣告要求失敗,因為特權程序不允許使用 WebView。 | 
 | 
| 網路連線速度緩慢,導致廣告請求失敗。 | 請改善網路連線,然後再試一次。 | |
| com.google.android.gms.ads.nonagon.load.a | 廣告請求逾時。 | |
| com.google.android.gms.ads.internal.util.*: Error while
    connecting to ad server: Unable to resolve host "pubads.g.doubleclick.net":
    No address associated with hostname | 由於網路連線問題,廣告請求失敗。 | |
| com.google.android.gms.ads.internal.util.*: Error building
    request URL: Cannot determine request type. Is your ad unit id correct? | 廣告單元 ID 不符合預期的規則運算式。 | 確認廣告單元 ID 正確無誤。 | 
| com.google.android.gms.ads.internal.render.bt: Unable to
    instantiate mediation adapter class. | Google Mobile Ads SDK 找不到中介服務轉接程式。 | |
| com.google.android.gms.internal.ads.*: Received error HTTP response code: 403 | Ad Manager 伺服器拒絕了要求。 | 請稍後再試。如果問題持續發生,請使用廣告檢查工具擷取要求網址,然後聯絡支援團隊。 |