亚马逊广告api崩溃我的应用程序?

时间:2014-03-23 10:04:32

标签: java android eclipse amazon-web-services

无法实例化以下类: - com.amazon.device.ads.AdLayout(Open Class,Show Error Log) 有关详细信息,请参阅错误日志(窗口>显示视图)。 提示:在Eclipse中显示时,在自定义视图中使用View.isInEditMode()来跳过代码

java.lang.NoClassDefFoundError: Could not initialize class android.os.Environment
    at com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:75)
    at com.amazon.device.ads.InternalAdRegistration.<init>(InternalAdRegistration.java:52)
    at com.amazon.device.ads.InternalAdRegistration.getInstance(InternalAdRegistration.java:64)
    at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:185)
    at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:176)
    at com.amazon.device.ads.AdLayout.<init>(AdLayout.java:120)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(    at sun.reflect.NativeConstructorAccessorImpl.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:373)

我的main.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="fill_parent"
android:layout_height="wrap_content" />

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

我的MainActivity.java就是这个

import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;

@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);
    ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
    setContentView(R.layout.main);

    AdRegistration.setAppKey("Application_Key");
    this.adView = (AdLayout) findViewById(R.id.myAdView);
    this.adView.loadAd(new AdTargetingOptions());

    button1 = preferences.getInt("DigitButtonStyle", defaultValue);
    buttonmadd = preferences.getInt("MemoryButtonStyle", defaultValue);
    buttoncos = preferences.getInt("FunctionButtonStyle", defaultValue);

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并遵循亚马逊开发人员指南。要解决此问题,只需复制amazon库并将其粘贴到libs文件夹中,然后再运行。

答案 1 :(得分:0)

这是Eclipse ADT插件中的已知问题,即使您使用View.isInEditMode(),在某些情况下,它会在最近的API版本(高于18)中崩溃。它已在Android Studio中修复。

如果您想查看布局预览,可以尝试使用低于19的不同API版本。

检查屏幕截图。它使用的是API 18.(Red box是Amazon AdLayout)

enter image description here