My android application crashes every time I run/launch it on both the emulator and a real device and returns this error message: Unfortunately "application_name" has stopped!
This is what my logcat looks like:
08-05 22:34:24.452: D/dalvikvm(541): Not late-enabling CheckJNI (already on)
08-05 22:34:25.012: D/AndroidRuntime(541): Shutting down VM
08-05 22:34:25.012: W/dalvikvm(541): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-05 22:34:25.012: E/AndroidRuntime(541): FATAL EXCEPTION: main
08-05 22:34:25.012: E/AndroidRuntime(541): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.tutorial.sharedpreferences/com.tutorial.sharedpreferences.Main}: java.lang.NullPointerException
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.os.Looper.loop(Looper.java:137)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-05 22:34:25.012: E/AndroidRuntime(541): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 22:34:25.012: E/AndroidRuntime(541): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 22:34:25.012: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-05 22:34:25.012: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-05 22:34:25.012: E/AndroidRuntime(541): at dalvik.system.NativeStart.main(Native Method)
08-05 22:34:25.012: E/AndroidRuntime(541): Caused by: java.lang.NullPointerException
08-05 22:34:25.012: E/AndroidRuntime(541): at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:153)
08-05 22:34:25.012: E/AndroidRuntime(541): at com.tutorial.sharedpreferences.Main.<init>(Main.java:13)
08-05 22:34:25.012: E/AndroidRuntime(541): at java.lang.Class.newInstanceImpl(Native Method)
08-05 22:34:25.012: E/AndroidRuntime(541): at java.lang.Class.newInstance(Class.java:1319)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
08-05 22:34:25.012: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
08-05 22:34:25.012: E/AndroidRuntime(541): ... 11 more
You are attempting to call getSharedPreferences() from an initializer. You cannot safely call methods you inherit from Activity until after super.onCreate() is called.
Related
We tried integrating HelpStack by following steps given on GitHub, but we kept getting the following errors:
04-03 13:54:22.054 4638-4638/com.playerline.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.playerline.android/com.tenmiles.helpstack.activities.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.tenmiles.helpstack.activities.HSActivityParent.onCreate(HSActivityParent.java:48)
at com.tenmiles.helpstack.activities.HomeActivity.onCreate(HomeActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
I'm guessing it has something to do with the App Theme, which in our case is is Theme.AppCompat.NoActionBar.
I am trying to upload a text file to Amazon s3 from my android application. I am using the following code snippet provided by Amazon AWS.
private static CognitoCredentialsProvider sCredProvider;
public static CognitoCredentialsProvider getCredProvider(Context context) {
if(sCredProvider == null) {
Log.i("Util","reached utility");
Log.i("Util","Context"+context);
sCredProvider = new CognitoCredentialsProvider(
context,
Constants.AWS_ACCOUNT_ID,
Constants.COGNITO_POOL_ID,
Constants.COGNITO_ROLE_UNAUTH,
null);
Log.i("Util","returning scredprovider"+sCredProvider);
sCredProvider.refresh();
}
Log.i("Util","returning scredprovider"+sCredProvider);
return sCredProvider;
}
When the code passes through sCredProvider.refresh(); it throws the follow error.
08-05 02:21:24.908: E/AndroidRuntime(25712): FATAL EXCEPTION: main
08-05 02:21:24.908: E/AndroidRuntime(25712): java.lang.RuntimeException: Unable to create service network.NetworkService: android.os.NetworkOnMainThreadException
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2667)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.app.ActivityThread.access$1600(ActivityThread.java:153)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.os.Looper.loop(Looper.java:137)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.app.ActivityThread.main(ActivityThread.java:5227)
08-05 02:21:24.908: E/AndroidRuntime(25712): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 02:21:24.908: E/AndroidRuntime(25712): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-05 02:21:24.908: E/AndroidRuntime(25712): at dalvik.system.NativeStart.main(Native Method)
08-05 02:21:24.908: E/AndroidRuntime(25712): Caused by: android.os.NetworkOnMainThreadException
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
08-05 02:21:24.908: E/AndroidRuntime(25712): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-05 02:21:24.908: E/AndroidRuntime(25712): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-05 02:21:24.908: E/AndroidRuntime(25712): at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:278)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:162)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:645)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:480)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.http.AmazonHttpClient.executeHelper(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.http.AmazonHttpClient.execute(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityServiceClient.invoke(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityServiceClient.getOpenIdToken(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.auth.CognitoCredentialsProvider.startSession(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.amazonaws.auth.CognitoCredentialsProvider.refresh(Unknown Source)
08-05 02:21:24.908: E/AndroidRuntime(25712): at com.chan.censioevlog.Util.getCredProvider(Util.java:41)
08-05 02:21:24.908: E/AndroidRuntime(25712): at network.NetworkService.onCreate(NetworkService.java:55)
08-05 02:21:24.908: E/AndroidRuntime(25712): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2657)
08-05 02:21:24.908: E/AndroidRuntime(25712): ... 10 more
Commenting out the line run the application fine. But I don't see the file uploaded to Amazon S3. I did setup to Amazon Cognito credential provider.
The source code can be found here.
CognitoCredentialsProvider.refresh() will make a network request to fetch Cognito identity id and session credentials if those aren't cached (handled by the provider itself). Based on the stack trace, you call getCredProvider(Context context) on the main thread. And refresh() is invoked on the main thread. That's why you see NetworkOnMainThreadException. To fix this issue, you can remove sCredProvider.refresh(). If for some reason you want to call refresh(), you need to call it in a background thread. Please refer to AsyncTask.
I am a trying to make video splitting app with the help of shorten example. I am trying to implement the following project from github.
https://github.com/dadachi/TestMp4parser.
but the app is not working and aborting.
LogCat -
08-05 17:03:42.161: D/OpenGLRenderer(6834): Enabling debug mode 0
08-05 17:03:44.934: D/do shoren starting(6834): do shoren starting
08-05 17:03:44.944: W/dalvikvm(6834): threadid=12: thread exiting with uncaught exception (group=0x4151e700)
08-05 17:03:44.944: E/AndroidRuntime(6834): FATAL EXCEPTION: doShorten
08-05 17:03:44.944: E/AndroidRuntime(6834): java.lang.RuntimeException: No box object found for ftyp
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.coremedia.iso.PropertyBoxParserImpl$FourCcToBox.invoke(PropertyBoxParserImpl.java:187)
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.coremedia.iso.PropertyBoxParserImpl.createBox(PropertyBoxParserImpl.java:90)
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.coremedia.iso.AbstractBoxParser.parseBox(AbstractBoxParser.java:87)
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.coremedia.iso.IsoFile.parse(IsoFile.java:85)
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.coremedia.iso.IsoFile.<init>(IsoFile.java:54)
08-05 17:03:44.944: E/AndroidRuntime(6834): at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:32)
08-05 17:03:44.944: E/AndroidRuntime(6834): at ek.shor.shortanproj.ShortenExample$1.run(ShortenExample.java:105)
08-05 17:03:44.944: E/AndroidRuntime(6834): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-05 17:03:44.944: E/AndroidRuntime(6834): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-05 17:03:44.944: E/AndroidRuntime(6834): at java.lang.Thread.run(Thread.java:841)
08-05 17:03:45.535: E/WindowManager(6834): Activity ek.shor.shortanproj.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41df8010 V.E..... R......D 0,0-729,192} that was originally added here
08-05 17:03:45.535: E/WindowManager(6834): android.view.WindowLeaked: Activity ek.shor.shortanproj.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41df8010 V.E..... R......D 0,0-729,192} that was originally added here
08-05 17:03:45.535: E/WindowManager(6834): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
08-05 17:03:45.535: E/WindowManager(6834): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
08-05 17:03:45.535: E/WindowManager(6834): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
08-05 17:03:45.535: E/WindowManager(6834): at android.app.Dialog.show(Dialog.java:281)
08-05 17:03:45.535: E/WindowManager(6834): at org.bestforce.utils.Ut.ShowWaitDialog(Ut.java:40)
08-05 17:03:45.535: E/WindowManager(6834): at ek.shor.shortanproj.ShortenExample.doShorten(ShortenExample.java:82)
08-05 17:03:45.535: E/WindowManager(6834): at ek.shor.shortanproj.ShortenExample.shorten(ShortenExample.java:78)
08-05 17:03:45.535: E/WindowManager(6834): at ek.shor.shortanproj.MainActivity.onClick(MainActivity.java:50)
08-05 17:03:45.535: E/WindowManager(6834): at android.view.View.performClick(View.java:4240)
08-05 17:03:45.535: E/WindowManager(6834): at android.view.View$PerformClick.run(View.java:17721)
08-05 17:03:45.535: E/WindowManager(6834): at android.os.Handler.handleCallback(Handler.java:730)
08-05 17:03:45.535: E/WindowManager(6834): at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 17:03:45.535: E/WindowManager(6834): at android.os.Looper.loop(Looper.java:137)
08-05 17:03:45.535: E/WindowManager(6834): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-05 17:03:45.535: E/WindowManager(6834): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 17:03:45.535: E/WindowManager(6834): at java.lang.reflect.Method.invoke(Method.java:525)
08-05 17:03:45.535: E/WindowManager(6834): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-05 17:03:45.535: E/WindowManager(6834): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 17:03:45.535: E/WindowManager(6834): at dalvik.system.NativeStart.main(Native Method)
The files are same as in the git hub project. please let me know what mistake I am doing what all mistakes I am making.
The TestMp4Parser example is not updated. The Mp4Parser library has been updated and there are new methods to split and append the Videos.
I installed google play services in my sdk.
My xml file is attached below
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
But an exception is raised after compiling java file.
Complete Log file also attached.
08-05 06:02:06.686: D/AndroidRuntime(1236): Shutting down VM
08-05 06:02:06.686: W/dalvikvm(1236): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-05 06:02:06.847: E/AndroidRuntime(1236): FATAL EXCEPTION: main
08-05 06:02:06.847: E/AndroidRuntime(1236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewindia/com.example.viewindia.ViewIndia}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.os.Looper.loop(Looper.java:137)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-05 06:02:06.847: E/AndroidRuntime(1236): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 06:02:06.847: E/AndroidRuntime(1236): at java.lang.reflect.Method.invoke(Method.java:525)
08-05 06:02:06.847: E/AndroidRuntime(1236): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-05 06:02:06.847: E/AndroidRuntime(1236): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 06:02:06.847: E/AndroidRuntime(1236): at dalvik.system.NativeStart.main(Native Method)
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-05 06:02:06.847: E/AndroidRuntime(1236): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Activity.setContentView(Activity.java:1895)
08-05 06:02:06.847: E/AndroidRuntime(1236): at com.example.viewindia.ViewIndia.onCreate(ViewIndia.java:25)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Activity.performCreate(Activity.java:5133)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-05 06:02:06.847: E/AndroidRuntime(1236): ... 11 more
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Fragment.instantiate(Fragment.java:592)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Fragment.instantiate(Fragment.java:560)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Activity.onCreateView(Activity.java:4738)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
08-05 06:02:06.847: E/AndroidRuntime(1236): ... 21 more
08-05 06:02:06.847: E/AndroidRuntime(1236): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.example.viewindia-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.viewindia-2, /system/lib]]
08-05 06:02:06.847: E/AndroidRuntime(1236): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-05 06:02:06.847: E/AndroidRuntime(1236): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-05 06:02:06.847: E/AndroidRuntime(1236): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-05 06:02:06.847: E/AndroidRuntime(1236): at android.app.Fragment.instantiate(Fragment.java:582)
08-05 06:02:06.847: E/AndroidRuntime(1236): ... 24 more
How can I solve this problem?
You have to add the Google Play Service SDK as a project in your workspace (assuming you're using Eclipse). This is described here.
The next step is to link this project with your Android project as a library. Here's the docu about this step.
I have programmed a simple app for testing some things.
One thing is AdMob.
On most of the Android Phone it works, but on Galaxy S3 or Galaxy Nexus, or on Tablets not. Maybe there is a Problem with the higher resoltuion?
The problem is that the app closes immediately when it starts. I tried to integrate AdMob on XML, but that does not work with the new version really.
Here is my AdMob Code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
AdView adView = new AdView(this, AdSize.BANNER, "replaced id with this");
//adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
LinearLayout layout = (LinearLayout)findViewById(R.id.LayoutMain);
layout.addView(adView,0);
adView.loadAd(adRequest);
And here is the LogCat
12-20 18:39:18.056: I/dalvikvm(541): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-20 18:39:18.066: I/dalvikvm(541): at dalvik.system.NativeStart.main(Native Method)
12-20 18:39:18.086: D/AndroidRuntime(541): Shutting down VM
12-20 18:39:18.096: W/dalvikvm(541): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-20 18:39:18.206: E/AndroidRuntime(541): FATAL EXCEPTION: main
12-20 18:39:18.206: E/AndroidRuntime(541): java.lang.RuntimeException: Unable to start activity ComponentInfo{at.android.dertestloerk/at.android.dertestloerk.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.os.Looper.loop(Looper.java:137)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-20 18:39:18.206: E/AndroidRuntime(541): at dalvik.system.NativeStart.main(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-20 18:39:18.206: E/AndroidRuntime(541): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Activity.setContentView(Activity.java:1835)
12-20 18:39:18.206: E/AndroidRuntime(541): at at.android.dertestloerk.MainActivity.onCreate(MainActivity.java:27)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Activity.performCreate(Activity.java:4465)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 11 more
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: java.lang.reflect.InvocationTargetException
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Constructor.constructNative(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 23 more
12-20 18:39:18.206: E/AndroidRuntime(541): Caused by: java.lang.OutOfMemoryError
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.nativeCreate(Native Method)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.content.res.Resources.loadDrawable(Resources.java:1937)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.View.<init>(View.java:2780)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.View.<init>(View.java:2717)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.view.ViewGroup.<init>(ViewGroup.java:379)
12-20 18:39:18.206: E/AndroidRuntime(541): at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
12-20 18:39:18.206: E/AndroidRuntime(541): ... 26 more
12-20 18:39:23.096: I/Process(541): Sending signal. PID: 541 SIG: 9
And here is my XML Layout
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/hintergrund"
android:orientation="vertical"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageViewLoerg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="#drawable/animatedloerg"
tools:ignore="ContentDescription" /> </LinearLayout>
Hope you can help .-)
This has nothing to do with Admob. The error is at:
18:39:18.206: E/AndroidRuntime(541): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout 12-20 18:39:18.206: E/AndroidRuntime(541): at
Ie it is crashing trying to load the XML layout, long before you programmatically ad in the Admob AdView.
Look at your layout, there is a problem there.