2012-06-07 2 views
0

나는 admob에서 새롭다. 나는 약간의 실수와 혼란 스러움을 가지고있다 .... 누군가 도와 줄 수 있니? 매번 앱을 시작하면 강제 종료됩니다. 전에 admob없이 시도했기 때문에 응용 프로그램 자체가 작동하는 것을 압니다. 여기 내 주요 클래스가 있습니다 : package com.firecow.markcheck;Admob newbie, Not working

package com.firecow.markcheck; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.text.Editable; 
import android.view.View; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.LinearLayout; 
import android.widget.Toast; 
import com.google.ads.*; 

public class MarkCheck extends Activity { 
    /** Called when the activity is first created. */ 

    Button sub, share; 
    EditText per; 
    Context context; 
    CharSequence text; 
    String heightString; 
    double num; 
    Toast toast; 
    MediaPlayer player; 
    private AdView adView; 
    AdRequest adRequest = new AdRequest(); 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.main); 
     sub = (Button) findViewById(R.id.bSubmit); 
     share = (Button) findViewById(R.id.bShare); 
     per = (EditText) findViewById(R.id.tePercent); 
     context = getApplicationContext(); 
     final int duration = Toast.LENGTH_SHORT; 
     adRequest.addTestDevice(AdRequest.TEST_EMULATOR);    // Emulator 
     adRequest.addTestDevice("EMJY-KBBS-VL7P-2");      // Test Android Device 

     //Create the adView 
     adView = new AdView(this, AdSize.BANNER, "a14fd022edb48e8"); 

     // Lookup your LinearLayout assuming it’s been given 
     // the attribute android:id="@+id/mainLayout" 
     LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout); 

     // Add the adView to it 
     layout.addView(adView); 

     // Initiate a generic request to load it with an ad 
     adView.loadAd(adRequest); 

     text = "Made by Firecow, Voice of William Wang"; 
     toast = Toast.makeText(context, text, duration); 
     toast.show(); 

     sub.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       heightString = per.getText().toString(); 
       if (heightString != null) { 
        num = Double.parseDouble(heightString); 

        if (num >= 151) { 
         text = "I didn't know you could score that high..."; 
         toast = Toast.makeText(context, text, duration); 
         toast.show(); 
        } else if (num >= 101) { 
         text = "You get a A+"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.perfect); 
         player.start(); 
         toast.show(); 
        } else if (num >= 86) { 
         text = "You get a A"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.harvard); 
         player.start(); 
         toast.show(); 
        } else if (num >= 73) { 
         text = "You get a B"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.ucla); 
         player.start(); 
         toast.show(); 
        } else if (num >= 68) { 
         text = "You get a C+"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.kwantlan); 
         player.start(); 
         toast.show(); 
        } else if (num >= 60) { 
         text = "You get a C"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.wendys); 
         player.start(); 
         toast.show(); 
        } else if (num >= 50) { 
         text = "You get a C-"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.drop_out); 
         player.start(); 
         toast.show(); 
        } else if (num <= 49) { 
         text = "You get a F"; 
         toast = Toast.makeText(context, text, duration); 
         player = MediaPlayer.create(getApplicationContext(), 
           R.raw.failure); 
         player.start(); 
         toast.show(); 
        } else { 
         text = "Please type a proper percent"; 
         toast = Toast.makeText(context, text, duration); 
         toast.show(); 
        } 
       } else { 
        text = "Please enter a proper percent"; 
        toast = Toast.makeText(context, text, duration); 
        toast.show(); 
       } 

      } 
     }); 

     share.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent bacon = new Intent("com.firecow.markcheck.SHARE"); 
       startActivity(bacon); 

      } 
     }); 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     try { 
      if (adView != null) { 
       adView.destroy(); 
      } 
      player.release(); 

      finish(); 
     } catch (Exception E) { 

     } 
    } 
} 

내 매니페스트 :

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

    <uses-sdk 
     android:minSdkVersion="7" 
     android:targetSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".MarkCheck" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".Share" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.firecow.markcheck.SHARE" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.google.ads.AdActivity" 
      /> 
    </application> 

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

</manifest> 

임 soooo를 혼란 ... 도와주세요! 모든

+0

logcat도 게시하십시오. –

답변

0

첫째, documentation 당, 당신은 configChanges을의와 매니페스트에 AdActivity를 지정해야합니다

<activity android:name="com.google.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

또한, 당신의 main.xml에이 ID mainLayoutLinearLayout 요소를 가질 필요가있다. 당신이 참고로, 마지막으로 layout.addView(adView);

를 호출 할 때 그렇지 않으면 프로그램이 충돌, 다음이 작동하지 않습니다

adRequest.addTestDevice("EMJY-KBBS-VL7P-2"); 

장치 ID는 32 진수 해시 문자열입니다. 로깅 구문을 보려면 logcat을 조사해야합니다.

To get test ads on this device, call adRequest.addTestDevice("some_32_hex_string") 

대신 해당 문자열을 입력하십시오.

+0

매니페스트에서 모든 항목을 검사했지만 여전히 작동하지 않습니다. 오류 : 오류 : 문자열 유형이 허용되지 않습니다 (값이 'configChanges'일 때 키보드 | keyboardHidden | 방향 | screenLayout | uiMode | screenSize | smallestScreenSize '). – naughtyburritos

+0

Android 3.2 이상으로 컴파일해야합니다 (project.properties에서'target = android-13' 이상 설정). 물론 3.2 이상의 Android SDK를 다운로드해야합니다. 'minSdkVersion = 7'을 (를) 가지고 있기 때문에 앱은 여전히 ​​Android 2.1에서 실행됩니다. –

+0

Android 2.1에서도 여전히 광고가 게재됩니까? – naughtyburritos