Android的AD浏览报的NoClassDefFoundError [英] Android AdView NoClassDefFoundError

查看:116
本文介绍了Android的AD浏览报的NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的开发初学者。我刚刚发布了一个应用程序,但发现了一些小问题,所以我想通过创建具有相同的包名称的发布应用程序的一个新的Andr​​oid项目纠正这些故障。但是,一旦我和更新应用程序完成后,这个程序是无法在手机上(调试)运行。说不幸的是thisApp已经停止。并且还即时通讯试图将AdMob的这个时候。

I'm a Beginner in Android Development. I just released an app but found some glitches, so I thought of correcting those glitches by creating a new Android project with the same package name as that of the released app. But once I finished with the update app, This app is not running on phone(debugging). Says "Unfortunately thisApp has Stopped." And also im trying to incorporate adMob this time.

请帮我,因为我必须尽快发布此。

Please help me because I have to publish this asap.

这里是曾经的logcat的应用程序崩溃:

Here's the Logcat once the app crashes :

08-11 18:14:31.063: E/dalvikvm(15877): Could not find class 'com.google.ads.AdView', referenced from method com.gamerspitch.easybluetooth.BlueActivity.initAdView
08-11 18:14:31.254: E/AndroidRuntime(15877): FATAL EXCEPTION: main
08-11 18:14:31.254: E/AndroidRuntime(15877): java.lang.NoClassDefFoundError: com.google.ads.AdView
08-11 18:14:31.254: E/AndroidRuntime(15877):    at com.gamerspitch.easybluetooth.BlueActivity.initAdView(BlueActivity.java:107)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at com.gamerspitch.easybluetooth.BlueActivity.onCreate(BlueActivity.java:40)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.Activity.performCreate(Activity.java:5133)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.os.Looper.loop(Looper.java:137)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at android.app.ActivityThread.main(ActivityThread.java:5103)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at java.lang.reflect.Method.invokeNative(Native Method)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at java.lang.reflect.Method.invoke(Method.java:525)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-11 18:14:31.254: E/AndroidRuntime(15877):    at dalvik.system.NativeStart.main(Native Method)

下面是我的AdMob安置的XML。我只是跟着此链接添加AdMob的。

Here is the XML of my admob placement. I just followed this link to Add admob.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/easyb"
tools:context=".BlueActivity" >

<LinearLayout
    android:id="@+id/adviewPlaceholder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >
</LinearLayout>

//Other elements

和我已经把这个在我的清单文件>

And I've put this in my manifest file >

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

    </activity>

这在我的活动onCreate方法>

And this in my Activity onCreate method >

private AdView ad;


@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blue);

    initAdView();
//Other elements
protected void initAdView() {

    ad = new AdView(this, AdSize.SMART_BANNER, "a15204b9eb97566");

    LinearLayout ll = (LinearLayout)findViewById(R.id.adviewPlaceholder);

    ll.addView(ad);

    ad.loadAd(new AdRequest());
}

protected void destroyAdView() {
    if(ad != null) ad.destroy();
}

@Override
protected void onDestroy() {    
    // destroy the ad when the activity is destroyed
    destroyAdView();
    super.onDestroy();
}

在此先感谢

推荐答案

根据这一行中的错误信息:

According to this line in the error message:

二月8号至11号:28:56.973:E / AndroidRuntime(27461):   java.lang.RuntimeException的:无法启动的活动   ComponentInfo {com.gamerspitch.easybluetooth / com.gamerspitch.easybluetooth.BlueActivity}:   android.view.InflateException:二进制XML文件中的行#9:错误   充气类com.google.ads.AdView

08-11 02:28:56.973: E/AndroidRuntime(27461): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gamerspitch.easybluetooth/com.gamerspitch.easybluetooth.BlueActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.google.ads.AdView

有一个与你的AD浏览报,导致应用程序崩溃的问题。

There is a problem with your AdView that causes the app to crash.

能否请您发表您的.xml布局文件和活动。

Could you please post your .xml layout file as well as the Activity.

更新:

为了使这一点更加清晰。我从来没有定义的.xml AD浏览报。我简单地创建里面我没有孩子的布局.xml文件布局,并通过code我AD浏览报添加到它。它看起来是这样的:

In order to make this a bit more clear. I never define the AdView in .xml. I simply create a Layout inside my layout .xml file that has no children, and via code I add the AdView to it. It looks like this:

      private AdView ad;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          setContentView(R.layout.yourlayout);

          initAdView();

          // other code...
      }

       protected void initAdView() {

            ad = new AdView(this, AdSize.SMART_BANNER, "MY_AD_UNIT_ID");

            LinearLayout ll = (LinearLayout) findViewById(R.id.adviewPlaceholder);

            ll.addView(ad);

            ad.loadAd(new AdRequest());
        }

        protected void destroyAdView() {
            if(ad != null) ad.destroy();
        }

        @Override
        protected void onDestroy() {    
            // destroy the ad when the activity is destroyed
            destroyAdView();
            super.onDestroy();
        }

和布局yourlayout.xml文件:

And the Layout yourlayout.xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent >

    <!-- lots of other layout stuff here -->


    <!-- make the adview be on the bottom of the screen -->
    <LinearLayout
        android:id="@+id/adviewPlaceholder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >
    </LinearLayout>
 </RelativeLayout>

这篇关于Android的AD浏览报的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆