无法实例化以下类: - com.amazon.device.ads.AdLayout

时间:2014-03-23 17:18:00

标签: java android eclipse amazon-web-services

这是日食在其布局编辑器中显示的 提示:在Eclipse中显示时,在自定义视图中使用View.isInEditMode()来跳过代码

这是什么意思?这是更详细的错误 java.lang.NoClassDefFoundError:无法初始化类android.os.Environment     在com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:78)     在com.amazon.device.ads.InternalAdRegistration。(InternalAdRegistration.java:58)     在com.amazon.device.ads.InternalAdRegistration。(InternalAdRegistration.java:54)     在com.amazon.device.ads.AdLayout.initialize(AdLayout.java:203)     在com.amazon.device.ads.AdLayout.initialize(AdLayout.java:183)     在com.amazon.device.ads.AdLayout。(AdLayout.java:127)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(at sun.reflect.NativeConstructorAccessorImpl.newInstance(at sun.reflect.DelegatingConstructorAccessorImpl.newInstance)at at java.lang.reflect.Constructor.newInstance(at com.android.ide.eclipse.adt.internal) .editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)     在com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)     在android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)     在android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)     在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)     在android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)     在android.view.LayoutInflater.rInflate(LayoutInflater.java:727)     在android.view.LayoutInflater.inflate(LayoutInflater.java:492)     在android.view.LayoutInflater.inflate(LayoutInflater.java:373)

我尝试使用代码和xml集成广告,但没有任何作用? 这是我的xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="top|center_horizontal" >

<com.amazon.device.ads.AdLayout  
android:id="@+id/myAdView" 
android:layout_width="match_parent"
android:layout_height="wrap_content" />

我正在使用他们的sdk中的amazon-ads-5.1.153.jar。这是我的main.java

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    int defaultValue = R.drawable.blue;
    int themedefault = ThemeChanger.THEME_BLUE;
    appliedtheme = preferences.getInt("mytheme", themedefault);
    AdLayout adView;
    ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
    setContentView(R.layout.main);

    AdRegistration.setAppKey("AppKey");
    adView = new AdLayout(this);
    adView.loadAd(new AdTargetingOptions());

    AdRegistration.enableTesting(true);
    AdRegistration.enableLogging(true);

    AdTargetingOptions adOptions = new AdTargetingOptions();    
    adView.loadAd(adOptions);

有没有人遇到过这个问题。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以在java代码中将广告视为

private static final String APP_KEY =“your app key”;     private static final String LOG_TAG =“adsample”;

AdLayout ad;
ViewGroup adcon;

this.adcon =(FrameLayout)findViewById(R.id.root_layout);

     AdRegistration.enableLogging(true);
        // For debugging purposes flag all ad requests as tests, but set to false for production builds.
        AdRegistration.enableTesting(true);

        try {
            AdRegistration.setAppKey(APP_KEY);
        } catch (final IllegalArgumentException e) {
            Log.e(LOG_TAG, "IllegalArgumentException thrown: " + e.toString());
            return;
        }

        ad = new AdLayout(this,AdSize.SIZE_300x250);
        LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);

        ad.setLayoutParams(layoutParams);
        ad.loadAd();
        adcon.addView(ad);

这确实有效