question

Amazon Customer avatar image
Amazon Customer asked

Problem with setAppKey / Mobile Ads API Jar

I'm a brand new Kindle Fire developer, and I'm having trouble with the Quick Start guide. My app now always crashes before successfully launching -- both on the emulator and on my connected first-generation Kindle Fire -- whenever I include even a single line of code related to mobile ads. It crashes if I include this instruction in my onCreate() method. AdRegistration.setAppKey(" // this is where i put my API key "); ...or even if I include an AdLayout object in my main XML file (cut-and-pasted from the sample code). It might be related to the Mobile Ads API jar, but I *think* I've got that installed properly. I followed the instructions, and I see it now in my "Referenced Libaries" folder. In the problems window, I am getting a warning (but not an error) about not targeting the latest versions of Android ("compatibility modes apply"), but I've tried most of the available Targets and API levels, and none of them clear up the problem. Are there additional import statements I need, beyond... import com.amazon.device.ads.AdLayout; import com.amazon.device.ads.AdRegistration; import com.amazon.device.ads.*;
fire tablet
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi, Thank you for posting and welcome to Kindle development. Can you see the exception stack trace in logcat while just crash happens? Could you please post it?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Amazon Customer avatar image
Amazon Customer answered
Here's all the messages that I see in Logcat... 08-26 08:39:32.697: D/AndroidRuntime(2381): Shutting down VM 08-26 08:39:32.697: W/dalvikvm(2381): threadid=1: thread exiting with uncaught exception (group=0x40015560) 08-26 08:39:32.713: E/AndroidRuntime(2381): FATAL EXCEPTION: main 08-26 08:39:32.713: E/AndroidRuntime(2381): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thursday/com.example.thursday.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class com.amazon.device.ads.AdLayout 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.os.Handler.dispatchMessage(Handler.java:99) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.os.Looper.loop(Looper.java:130) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-26 08:39:32.713: E/AndroidRuntime(2381): at java.lang.reflect.Method.invokeNative(Native Method) 08-26 08:39:32.713: E/AndroidRuntime(2381): at java.lang.reflect.Method.invoke(Method.java:507) 08-26 08:39:32.713: E/AndroidRuntime(2381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850) 08-26 08:39:32.713: E/AndroidRuntime(2381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608) 08-26 08:39:32.713: E/AndroidRuntime(2381): at dalvik.system.NativeStart.main(Native Method) 08-26 08:39:32.713: E/AndroidRuntime(2381): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class com.amazon.device.ads.AdLayout 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 08-26 08:39:32.713: E/AndroidRuntime(2381): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.Activity.setContentView(Activity.java:1659) 08-26 08:39:32.713: E/AndroidRuntime(2381): at com.example.thursday.MainActivity.onCreate(MainActivity.java:31) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 08-26 08:39:32.713: E/AndroidRuntime(2381): ... 11 more 08-26 08:39:32.713: E/AndroidRuntime(2381): Caused by: java.lang.ClassNotFoundException: com.amazon.device.ads.AdLayout in loader dalvik.system.PathClassLoader[/data/app/com.example.thursday-1.apk] 08-26 08:39:32.713: E/AndroidRuntime(2381): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 08-26 08:39:32.713: E/AndroidRuntime(2381): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 08-26 08:39:32.713: E/AndroidRuntime(2381): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.createView(LayoutInflater.java:471) 08-26 08:39:32.713: E/AndroidRuntime(2381): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570) 08-26 08:39:32.713: E/AndroidRuntime(2381): ... 20 more
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi, So the problem is this java.lang.ClassNotFoundException: com.amazon.device.ads.AdLayout I think the ads sdk jar is not exported in the apk. It's only set the compile classpath. Can you add check-mark next to amazon-ads-5.1.14.jar in Java Build Path -> Order and Export of your project. - close eclipse - add manually the sdk ad jar file in your project's "libs" folder - open eclipse - refresh your project till the sdk jar appears on libs folder - go to your project's properties > Java Build Path > Library Tab and choose amazon-ads-5.1.14.jar instead of an external one. and select the sdk from the list below. - go to "Order and Export" tab and select again the SDK - click ok AND ITS DONE.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Amazon Customer avatar image
Amazon Customer answered
Thanks for the support! The problem was just that I hadn't checked the checkbox for that library at the left of the "Order and Export" tab. So while it was appearing on the list of libraries that were available in Eclipse, it wasn't actually selected as a library to be used with my app!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.