Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AdMob集成到Android应用程序的问题_Android_Sdk_Admob_Instructions - Fatal编程技术网

AdMob集成到Android应用程序的问题

AdMob集成到Android应用程序的问题,android,sdk,admob,instructions,Android,Sdk,Admob,Instructions,我对Java和Android应用非常陌生,因此,虽然这对其他人来说可能是蛋糕,但它让我有些头疼。 应用程序应加载、播放声音文件并关闭。没有AdMob也可以正常工作。 使用AdMob,它会启动、振动一次(正常版本中没有),正常运行,然后卡住、振动3次,然后关闭,并抛出一个“对不起!应用程序名称(process process.NAME)意外停止。请重试” 我正在使用我的第二个应用程序,也是我的第一个AdMob集成 我遵循的SDK说明: 我所做的: -已注册 -获得SDK -添加了.jar -在An

我对Java和Android应用非常陌生,因此,虽然这对其他人来说可能是蛋糕,但它让我有些头疼。

应用程序应加载、播放声音文件并关闭。没有AdMob也可以正常工作。

使用AdMob,它会启动、振动一次(正常版本中没有),正常运行,然后卡住、振动3次,然后关闭,并抛出一个“对不起!应用程序名称(process process.NAME)意外停止。请重试”

我正在使用我的第二个应用程序,也是我的第一个AdMob集成

我遵循的SDK说明:

我所做的:
-已注册
-获得SDK
-添加了.jar
-在AndroidManifest.xml的末尾添加SDK说明中的发布IDAdMobility定义和跟踪市场安装代码,并编辑发布ID
-已添加internet权限
-还添加了“ADMOB\u允许广告的位置”
-将“AdMob AdView Attributes”添加到attrs.xml(我使用Eclipse,因此我首先尝试将其添加到res/values/strings.xml,然后创建一个新的xml并将代码添加到其中)



如果完整的代码是必要的,我会编辑这篇文章。感谢您的帮助。
提前谢谢你
克里斯


(LogCat在没有AdMob文件的情况下抛出两个小错误(I/-ed导入和AdView))
(带有AdMob的LogCat抛出此选项)


使用完整的.java和XML代码进行编辑。我对Java一窍不通,它与我通常使用的AS、PHP、JavaScript和其他web语言截然不同

KittyPurr.java

package seven.kitty.purr;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.admob.android.ads.AdManager;
import com.admob.android.ads.AdView;

public class KittyPurr extends Activity
{
  private MediaPlayer mMediaPlayer;
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
   playAudio();



  }

  private void playAudio () {
    try {
    mMediaPlayer = MediaPlayer.create(this, R.raw.purrr);
    mMediaPlayer.setLooping(false);
    Log.e("beep","started0");
    mMediaPlayer.start();

    AdView adView = (AdView)findViewById(R.id.ad);
    adView.requestFreshAd();

    mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
            public void onCompletion(MediaPlayer arg0) {
         finish();
      }
    });
    } catch (Exception e) {
    Log.e("beep", "error: " + e.getMessage(), e);
    }
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    if (mMediaPlayer != null) {
    mMediaPlayer.release();
    mMediaPlayer = null;
    }
  }
}


main.XML




attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</declare-styleable>
</resources>

他补充道

意味着要将文件添加到/libs?如果没有,请这样做

编辑:

您在创建时使用了错误的
onCreate
。应该是:

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 ...
}
如果您想在emulator中测试它,您需要在xml中添加以下内容
然后您需要设置**adrequest.setTestDevice(true)**
在AndroidManifest.xml中,您需要添加以下内容
还有一件事你需要考虑的是,你需要用Android 3.2或以上的项目来编译项目。

Plz发布logcat的输出。是的,我已将其添加到/libs,并将.jar添加到项目中。就像.pdf里说的那样
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr name="backgroundColor" format="color" />
<attr name="primaryTextColor" format="color" />
<attr name="secondaryTextColor" format="color" />
<attr name="keywords" format="string" />
<attr name="refreshInterval" format="integer" />
</declare-styleable>
</resources>
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 ...
}
you need to add the following this in xml and if you want to test it in emulator
  then u need to set the **adrequest.setTestDevice(true)**

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        **xmlns:myapp="http://schemas.android.com/apk/libs/com.google.ads"**
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <com.google.ads.AdView
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    **myapp:adUnitId="Your Admob ID"
    myapp:adSize="BANNER"**
    />
    </LinearLayout>


in the AndroidManifest.xml you need to add the following thing

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

and one thing you need to consider that u need to compile project with android 3.2 or above