廣告載入錯誤

如果廣告載入失敗,系統會呼叫回呼,並提供 LoadAdError 物件。

如果是 AdView,系統會呼叫下列項目:

以下範例顯示廣告無法載入時可用的資訊:

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(LoadAdError error) {
  // Gets the domain from which the error came.
  String errorDomain = error.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 = 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 additional response information about the request. See
  // https://developers.google.com/admob/android/response-info
  // for more information.
  ResponseInfo responseInfo = error.getResponseInfo();
  // Gets the cause of the error, if available.
  AdError cause = error.getCause();
  // All of this information is available using the error's toString() method.
  Log.d("Ads", error.toString());
}
如為網域下的錯誤 MobileAds.ERROR_DOMAIN, 請參閱「解決常見的加入程序問題」一文, 瞭解更詳細的說明,以及解決問題的可能做法。

偵錯常見的錯誤記錄訊息

在 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
  • 檢查網際網路設定。
  • 移除 android:sharedUserId="android.uid.system",然後將應用程式安裝為系統應用程式。
網路連線速度緩慢,導致廣告請求失敗。 請改善網際網路連線品質,然後再試一次。
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 找不到中介服務介面卡。
  • 使用廣告檢查器查看可用的中介服務,診斷 Google Mobile Ads SDK 找不到哪些中介服務。
  • 在專案中新增缺少的轉接程式。如要瞭解如何為每個廣告來源完成這個步驟,請參閱 網路詳細資料
com.google.android.gms.internal.ads.*: Received error HTTP response code: 403 AdMob 伺服器拒絕了要求。 請稍後再試。如果問題可重複發生,請使用廣告檢查工具擷取要求網址,然後聯絡支援團隊。