2014-11-23 3 views
1

주요 활동 자바 파일 :java.lang.RuntimeException가 : 바이너리 XML 파일 라인 # 8 :

public class MainActivity extends AndroidApplication { 
    private InterstitialAd interstitial; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); 
     cfg.useGL20 = false; 

     initialize(new Library(), cfg); 

     setContentView(R.layout.activity_main); 

     // Prepare the Interstitial Ad 
     interstitial = new InterstitialAd(MainActivity.this); 
     // Insert the Ad Unit ID 
     interstitial.setAdUnitId("ca-app-pub-123456789/123456789"); 

     //Locate the Banner Ad in activity_main.xml 
     AdView adView = (AdView) this.findViewById(R.id.adView); 

     // Request for Ads 
     AdRequest adRequest = new AdRequest.Builder() 

     // Add a test device to show Test Ads 
     .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
     .addTestDevice("CC5F2C72DF2B356BBF0DA198") 
       .build(); 

     // Load ads into Banner Ads 
     adView.loadAd(adRequest); 

     // Load ads into Interstitial Ads 
     interstitial.loadAd(adRequest); 

     // Prepare an Interstitial Ad Listener 
     interstitial.setAdListener(new AdListener() { 
      public void onAdLoaded() { 
       // Call displayInterstitial() function 
       displayInterstitial(); 
      } 
     }); 

    } 
    public void displayInterstitial() { 
     // If Ads are loaded, show Interstitial else show nothing. 
     if (interstitial.isLoaded()) { 
      interstitial.show(); 
     } 
    } 
} 

Actvity main.xml에

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-123456789/123456789" /> 

</LinearLayout> 
활동 ComponentInfo {} android.view.InflateException을 시작할 수 없습니다

Mainfest XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.neodots.Library" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="1" android:targetSdkVersion="17" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="landscape" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> 
    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

    </application> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
</manifest> 

오류 :

11-22 11:23:55.144: E/AndroidRuntime(955): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.Library/com.neodots.Library.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.gms.ads.AdView 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.app.ActivityThread.access$600(ActivityThread.java:141) 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.os.Handler.dispatchMessage(Handler.java:99) 
11-22 11:23:55.144: E/AndroidRuntime(955): at android.os.Looper.loop(Looper.java:137) 

나는 안드로이드 코딩에 초보자입니다.이 튜토리얼을 사용하여 코드를 작성했습니다.하지만 지금은 오류가 많아서 애플리케이션을 실행할 수 없습니다. 해결할 수있는 사람은 누구나 될 수 있습니다. 미리 감사드립니다. .................................................. .........

+0

기기가 너무 오래되어 컴파일되는 API 때문에 비슷한 오류가 발생합니다. 'build.gradle' 파일을 수정 한 적이 있습니까? – Johnny

+0

에뮬레이터가 오래되었습니다. 실제로 libgdx를 사용하고 있습니다. 내 프로젝트에서 build.gradle을 찾을 수 없습니다. 설치하는 방법에 대해 도움이 될 수 있습니다 .. –

+0

프로젝트에서 Google Play 서비스 라이브러리를 참조한 적이 있습니까? –

답변

0

APK에 GooglePlayServices 라이브러리가 포함되어 있지 않은 것으로 보입니다. 비표준 방식으로 건물을 사용하고 있으므로 GPS 라이브러리가 APK에 포함되어 있는지 확인하는 방법에 대한 문서를 참조해야합니다.

+0

다음 단계에 따라 https://developer.android.com/google/play-services/setup.html –

+0

죄송합니다. "내가 튜토리얼을 따라 갔다"고 말했을 때 libgdx를 사용하면서 libgdx 빌드 mech를 사용하고 있다고 가정했습니다. 이 자습서의 중요한 제목은 "Google Play 서비스를 프로젝트에 추가"입니다. 자신의 환경에 적합한 지 확인하십시오. Android Studio, Eclipse, 다른 것을 사용하고 있습니까? – William

관련 문제