我相对较新的编程,我在Android应用程序中遇到广告问题。我的应用程序在启动时崩溃,我收到此错误:
02-08 20:52:47.321: E/AndroidRuntime(23492): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.Menu}: android.view.InflateException: Binary XML file line #38: Error inflating class com.google.android.gms.ads.AdView
继承我的活动:
public class Menu extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
String UrlPath="android.resource://"+getPackageName()+"/"+R.raw.menibg;
final VideoView gif = (VideoView)findViewById(R.id.banim);
gif.setVideoURI(Uri.parse(UrlPath));
gif.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
gif.start();
mp.setLooping(true);
}
});
AdView adView = (AdView) findViewById(R.id.ads);
AdRequest request = new AdRequest.Builder().build();
adView.loadAd(request);
final Intent intent = new Intent(this, MyActivity.class);
final Intent intent1 = new Intent(this, Achievements.class);
final ImageView bplay = (ImageView)findViewById(R.id.play);
final ImageView bachieve = (ImageView)findViewById(R.id.achievements);
final View.OnClickListener buttonClickListener;
buttonClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view == bplay){
startActivity(intent);
}else if (view == bachieve){
startActivity(intent1);
}
}
};
bplay.setOnClickListener(buttonClickListener);
bachieve.setOnClickListener(buttonClickListener);
}
}
和我的xml布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/banim"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:id="@+id/play"
android:src="@drawable/play"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/achievements"
android:src="@drawable/achievements"
/>
</LinearLayout>
</FrameLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitID="xxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdONCreate="true"
/>
</LinearLayout>
我发现了类似的问题,它应该与jar文件及其添加方式有关。我把它放在我的libs文件夹中并添加为库。也许应该编辑iml?我看不出有什么问题,可能是因为我缺乏经验。我希望我能在这里得到一些帮助。
我使用Intellij 11.1.2